About Scripting in Isight Models

You can use scripts in a number of places in Isight models to customize behavior.

Important:

There are two alternatives available to change configuration of component or plugin model elements, via scripting. You can either use the ComponentAPI and PluginAPI interfaces respectively, or you can directly modify the properties of DtComponent or DtPlugin objects.

  • The recommended alternative is to use the API interfaces, and call the component/plugin APIs as documented by specific components/plugins. And when you are done, you should call apply() method on the API interface to commit the changes. If you want to discard the changes, do not call the apply() method, just discard the API interface object, and the configuration changes will not be committed.
  • It is possible to directly modify the properties of component or plugin objects by invoking methods in DtComponent or DtPlugin interfaces, since these are also documented APIs. In this case, the modifications are committed immediately, and cannot be discarded. This is not the recommended alternative, because properties are not public interfaces of DtComponent and DtPlugin model elements. It is recommended to use ComponentAPI or PluginAPI interfaces as described above. Directly accessing the underlying properties may put them in an inconsistent state, and may corrupt the component/plugin instance. The intended use of DtComponent or DtPlugin interfaces is for custom component or plugin developers, and not to change the configuration of components or plugins via scripting.

In any case, you should never mix the usage of the two alternatives to configure the component via scripting.

This page discusses:

Using Scripts in Isight Models

You can use scripts in a number of places in Isight models to customize behavior.

You can use scripts in the following places:

  • The Script Component (as described in Script Component). This component is used to manipulate array and string parameters in ways that the Calculator component cannot handle.

  • Component Prologue/Epilogue Scripts (as described in Defining Prologue/Epilogue Information). Prologue scripts can be used to perform component reconfiguration during model execution or to set up files or other resources for the component to use. Epilogue scripts can be used to collect process output files or to calculate flags used in subsequent conditional simulation process flow expressions.

  • Model and Component Customization Scripts (as described in Customizing Models in the Isight User’s Guide). Customization scripts can reconfigure a model based on the model inputs, allowing more dynamic modeling.

    The same basic scripting facilities and editors are available in all of these locations.

Available Scripting Languages

Isight supports two scripting languages.

  • Jython. A version of the Python language written in Java.

  • DynamicJava. A scripting language that uses Java syntax.

Both languages provide access to parameters (or the value of a parameter), to select global variables that provide access to the Isight SDK, and to arbitrary Java classes and objects; however, the way in which they provide access differs slightly for each language. Jython is the recommended scripting language. It has a simpler syntax and more flexible type system than DynamicJava. DynamicJava is provided for backward compatibility with existing models.

Script Execution

The script is evaluated statement-by-statement at run time until the last statement completes.

When the script's last statement completes, the Script component is considered to have finished successfully. If any statement gets an error or the script throws an uncaught exception, the Script component is considered to have failed.

The standard exception to throw to indicate a failure is RtException. For example, using Jython syntax:

if not resultsUsable:
    raise RtException("the results are not usable")

Note: Scripts should be written carefully so as to not interfere with the environment used to execute them. For example, scripts cannot contain calls to System.exit() or Runtime.getRuntime().exit(), because these method calls would terminate the supporting Isight Gateway or SIMULIA Execution Engine station.