As you might have seen while running your current model, we had numerous rail cars differed by colors only. Phase 3 will be devoted to defining different types of the rail cars.
We provide you with the handy Rail Car Type creation Wizard. Simply specify the name of the new rail car type and choose the animation from the list of ready-to-use 3D objects.Create new rail car types
We use conditional operator to set the railcar type for the rail cars of the train being created. We want to diversify railcars of our freight train. The first railcar should be of type Locomotive. Successive railcars can be of any other railcar type.
creates a new train, it successively calls the expression specified in
the New rail car
field for every railcar of the train. Using the local variable carindex
we pass the index of the currently created
railcar to the expression.
The conditional operator allows you to choose between two given alternatives depending on the value of a Boolean expression. In our example, if the carindex == 0 expression evaluates to true, then the current railcar is the first car of the train and we set its type to Locomotive. Otherwise, the expression evaluates to false and for the successive railcars we call the randomlyCreate() function and provide the classes of the railcar types to randomly choose the types for other railcars in the train.
As a result, we will have a train with a loco as the first car, followed by ten rail cars of our custom rail car types.Watch the model in 3D mode
When you create a 3D window, AnyLogic adds a view area that allows you to easily navigate to the 3D view at runtime. To switch to this 3D view while the model is running, open the developer panel by clicking the Developer panel control in the right corner of the control panel. In the developer panel, expand the select view area to navigate list and select [window3d] from the list.
The view area expands the 3D animation scene to the model window's full size.
Reference model: Hump Yard - Phase 3