Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Create Objects in a Simulation

In a simulation model, you can create Classes and either create instances of them (Global Objects) to represent objects that exist in the process, or define Actions to generate one or more Objects at any point during the process.

You have three options for creating Objects in a simulation model:

  • Manually create the Object
  • Dynamically create an Object through a CreateObject Action element
  • Use the JavaScript function sim.CreateObject ("name") as the 'Effect' of an Action element, to again create an Object dynamically

Having created an Object dynamically you can also instantiate any inner objects of that Object, such as an Activity on a Class, and act on the properties of that inner object.

Manually Create an Object

Simply create an Object element on a diagram in the model, either by:

  • Dragging an Object element from the Object pages of the Diagram Toolbox and setting its classifier, or
  • Dragging a classifier element from the Project Browser and pasting it into the diagram as an instance

In the simulation model you can then set up the Object properties themselves (such as setting run-states to re-set the initial value of an attribute) or the behaviors of Actions to act on the Object (such as passing it along a process flow) and observe what happens to the Object in a simulation.

Create an Object through a CreateObject Action

If your process generates objects in runtime, you can simulate this using a CreateObject Action.



See also


On your Activity diagram, drag an 'Action' icon from the Diagram Toolbox, and select the 'Other | CreateObject' context menu option to define it as a CreateObject Action element.



Set the classifier of the CreateObject Action to the Class of which the Object will be an instance.

(Advanced | Set Classifier).

Create an Action Pin on the CreateObject Action, of kind output.

Action Pin


Create or select the next Action in the processing sequence, and add an Action Pin of kind input.

Connect the two Actions with a Control Flow connector, and the two Action Pins with an Object Flow connector.

Object Flow Control Flow


Perform a Simulation on the diagram. When the CreateObject Action is executed, it creates an Object having the properties of the classifier, and stores it in its Output Pin. The Object itself is passed through the Object Flow connection to the Input Pin of Action 2, where its properties can be listed in the Locals window for the simulation.

Create Object Using JavaScript

You also can create simulation objects dynamically using a Javascript command in the 'Effect' field of the Action element. The command is:

     sim.newObject = sim.CreateObject("ClassName");


     sim.newObject = new SimObject("ClassName"); (natural JavaScript)

That is: 'Simulate the creation of an Object based on Class <name>'. The classifying Class would exist in the same Package as the Action.

As for the CreateObject Action element, the Object is created during the simulation and can be passed down to and processed by 'downstream' elements. In this example, the created Object is identified as sim.object1 and in Action 2 it is accessed and one of its attributes given a different value (also by JavaScript as an Effect of the Action).

Instantiate Inner Objects

As described above, you can create an Object using either JavaScript or a CreateObject Action. Similarly, you can instantiate inner objects using Javascript or a CallBehavior Action.

In this example, using JavaScript, the simulation first creates a test object based on Class1. Class 1 has an Activity element and diagram, with an Activity Parameter 1 set to the integer 5 and an Activity Parameter 2 set to the string "test". The value of Activity Parameter 1 is captured as a buffer value 'buf'

Learn more