Shape Replication

AnyLogic supports shape replication - very easy and convenient way of creating a number of the same shapes. If you need to draw a set of shapes, you do not need to draw them individually one by one, you can just draw a shape once and specify how many copies you want to be created. You define the replication factor of the shape in the Replication edit box in the Advanced section of the properties of the shape. If you leave this field empty, only one shape will be created.

The given demonstration model shows how a railroad and a train can be animated by just one replicated rectangle and one replicated group containing three lines. To understand the approach, please study the dynamic properties of the rectangle and the group correspondingly.

Demo model: Shape Replication

You can replicate not only presentation shapes, but also controls and charts. Sometimes you need to create an array of similar controls e.g. to be able to change an array of similar objects at runtime. AnyLogic replicated controls may save you some drawing time and also may make your model scalable. You can take a look at the given demo model that contains a replicated button that is used it to change the fill color of a replicated shape. Moreover, the number of copies of the button and the shape is dynamically controlled by a slider in this model.

Demo model: Replicated Button


Shapes are represented as Java objects of ReplicatedShape class. You can access them as members of agent. Access individual elements of a replicated shape using get() function, passing the index of the shape in the vector of replicated shapes as an argument. You work with shapes using functions of the corresponding shape classes (see AnyLogic Class Reference for more information).

For instance, you change the X-coordinate of the second oval of the replicated shape named oval1 this way: oval1.get(1).setX(27)