Use the script operation, when you need to specify an inline expression in OCL 2.0, as Java binary, or in any of MagicDraw supported script languages. MagicDraw supports any script language that has a JSR-223-compliant engine.

Adding a script operation directly into a structured expression is the same as defining an operation in the model and then calling it from the structured expression.

To create a script operation


  1. Click Create operation on the left side of the dialog.
     
  2. Click the Script icon on the right side of the dialog.

  3. If needed, change the operation name.
  4. Click the three dots button next to the Style option to define the style for your script operation. 

    The Style option is available only in the Dependency Criteria and Relation Criteria dialogs.

  5. From the Language drop-down list, select a language.

    To ensure the best performance experience, it is strongly suggested that you use the recommended languages (Binary or Groovy). The icon color next to the language selection reflects performance, (i.e., green for fast, yellow for medium, and red for slow). If the performance is unknown, an info icon appears.

    If the engine of the language you need is not built into MagicDraw by default, you can add it to the application yourself. Make sure the Automaton plugin is enabled!

  6. Type in the Body box. Use the syntax of the selected language.
  7. In the Listeners Configuration box, type a reference to the java class, which specifies when the result of the script operation must be recalculated.

    The listeners configuration is not necessary, but using it can improve the performance.
    You can create your own listener using MagicDraw API.

  8. Click the three dots button next to the Results Filter By Type box and select one or more element types to filter the result of the script operation.
    The script operation is created. Now you can create a new one, where the result of the previously created operation is used as an argument.