NEW RELEASE! The 2022x Refresh2 Hot Fix 3 was released on February 28, 2025. For more information, see 2022x Refresh2 Hot Fix 3 Version News.

Manipulating run-time objects with scripts lets you dynamically control simulation environment, structural elements, and behavioral workflows. You can modify structural and global variables, invoke behaviors and operations. You can also create and send signals, and retrieve key runtime data like token values, simulation time, and callers of the scripts. Additionally, you can evaluate expressions and check behaviors to gain information about the simulation.

Action scripts can be used where the scripts are evaluated during simulation, for example in the Opaque Behaviors, Actions, Guards, or directly in the simulation Console pane). You can use the following types of action scripts to manipulate runtime objects:

  • fUML object syntax, which simplifies some ALH actions. Example: object.get("property")
  • ALH (Action Language Helper) scripts. Example: ALH.getValue(object, "property")

  • Alf - Action Language for fUML (requires an additional plugin). Example: object.property

It is easy to access elements that are deeper in the hierarchy tree, but accessing parent elements is more complicated. Therefore, it is important to plan where executing a particular script would be the most efficient.

Specifying context

Scripts are context sensitive, whenever you execute a script, you must specify its context (object). Mostly, it is the current simulation context (marked as "self" in a script). However, it can also be an input pin (pin name) or an object created in a script itself (see Creating a runtime object (Copy)). When evaluating from Simulation console, the context depends on the selected element in the variables pane. For example:

To get the Diameter Value Property when the script is executed in the Car Block, the script should be self.get("tyre.wheel.Diameter").


Getting the Diameter Value Property when the simulation context is the Car Block.

To get the Diameter Value Property when the script is executed after selecting the wheel, the script should be Diameter.

The first level properties can be directly accessed using their name.


Getting the Diameter Value Property when the script is executed in the Console pane.

Additional resources

  • You can find more examples of API usage at <install_root>\samples\simulation\SmallTestSamples.mdzip (Tests section). 
  • For more information, see the JavaDoc at <install_root>\openapidocs\SimulationJavaDoc.

Activity

All
Personal filters
All