Prev | Next |
Destroy Objects in a Simulation
Having created or generated Objects in your simulation model, you can define Actions to destroy those objects at any point during the process. All simulation objects are destroyed automatically when the simulation completes.
You have two options for destroying the Objects in your simulation model:
- Dynamically destroy the Objects through a DestroyObject Action element
- Dynamically destroy the Objects using JavaScript in an Action element
The result of the deletion can be observed in the change of local variables, on the Local window.
Destroy an Object through a DestroyObject Action
Step |
Action |
See also |
---|---|---|
1 |
On your Activity diagram, drag an 'Action' icon from the Diagram Toolbox, and select the 'Other | DestroyObject' context menu option to define it as a DestroyObject Action element. |
Action |
2 |
Set the classifier of the DestroyObject Action to the Class of which the Object is an instance. (Advanced | Set Classifier). Create an Action Pin on the DestroyObject Action, of kind input. |
Action Pin |
3 |
Connect the Input Action Pin to an Object Flow connector from the last Action that operated on the Object. In this example, the last Action that operated on the Object is the Action that created it.
|
Object Flow |
4 |
Perform a Simulation on the diagram. The process passes the Object name or value into the Input Action Pin as a parameter. When the DestroyObject Action is executed, it deletes the Object having that name or value from the model. In the example, the instance of Class1 is specifically destroyed before Action4 is processed, but the results of Action2 are unaffected. |
Destroy an Object using JavaScript
In the 'Properties' dialog of the Action element, in the 'Effect' field on the 'Effect' page, type either:
sim.DestroyObject ("objectname")
or
delete sim.objectFullName
For example:
Notes
Learn more