13.5. Using Macros in Process Templates

Macros can be defined in EKM Studio and then embedded in a process template to automate certain tasks.

You can embed a macro in a process template to:

Defining a Macro

To define a macro, select Edit > Script, and then type your script in the Edit Script dialog box. Note that you do not insert the <script> tag in the macro definition; this is added automatically by EKM Studio.

Figure 13.27:  Edit Script Dialog Box

Edit Script Dialog Box

You should define the macro using the scripting language (Python or Beanshell) displayed above the editing window. The scripting language for a process is set in your process attributes.

The name that you define for the macro in the script can then be entered in the process template definition dialog box so that it can be utilized.


Note:  Jython imposes a limit of 100 KB per script file. To avoid process errors it is recommended that you create scripts using the EKM scripting interface and store them in the /Administration/Configuration/Scripts folder. For details see Using EKM's Scripting Interface in the Administration Guide. Storing scripts in a centralized library makes them available for any process template, lifecycle, or custom type. See Configuring a Common Scripts Library in the Administration Guide for details.


Below is the bsh code for a sample macro named incrementMacro.

incrementMacro() {
   result = new HashMap();
   result.put("index", index+1);
return result;
}

The macro increments a variable named index by one and will be used by an auto node in a process. Once the code is entered in the Edit Script dialog box, the macro can be utilized in the auto node definition. Figure 13.28: Edit Auto Node With Macro shows where incrementMacro macro name is entered in the Edit Auto Node dialog box.

Figure 13.28:  Edit Auto Node With Macro

Edit Auto Node With Macro


If you are defining a macro that will extract the name of an assignee from a previous node in the process, the macro must take an argument that is the node name, and must return a string that is the name of the assignee. For example, you would specify foo(Run Analysis) when defining a macro named foo that will extract the assignee from a node named Run Analysis.

When specifying an assignee in the Edit Node or Edit Batch Node dialog box, use $ followed by the macro name in the Assignee field. For example, if the macro is named foo, you would enter $foo in the Assignee field.

Editing a Macro in an External Editor

If you want to edit the macro in an external editor, you must first select an editor to use. Click the Set external editor link. In the Set External Editor dialog box, browse your local file system to locate the executable of the application that you want to launch, and specify any command line arguments if desired.

Once you have selected the executable, the script opens in the selected application. The application that you chose will be remembered as the default external editor.

With a default editor specified you can click the Open with external editor link when editing any script to automatically open the script in the selected editor.

If you edit a script in an external editor, and then return to the script editor in EKM Studio, you will be asked if you want to load the edited script in EKM Studio’s editing window:

Click Yes to load the edited script, or No to discard the changes.


Release 18.2 - © ANSYS, Inc. All rights reserved.