Creating Macros

The Macros tab consists of a table where you can define and use macros.

To create a new macro:

  1. Scroll to the end of the table.

  2. Double-click the Name cell in the empty line.

  3. In the Name cell, enter the name of the macro, starting with a $ symbol to differentiate it from a built-in function.

    For example, to define a macro of a scaling function with two variables, enter $scale(x,y).

  4. Double-click the Expression cell to the right of the new macro name and enter the macro expression.

    Following the previous example, the expression to enter is (x+y)/norm(x+y)

  5. Leave the cell by pressing Enter or clicking somewhere outside of the cell.

    The expression is evaluated. If an error occurs when evaluating the expression, the calculator message log opens and displays the error message.

    A new line is added to the bottom of the table.

Now the macro is defied and can be used in the calculation, either by dragging it from the table to the text field or by typing it directly into the text field.

Macros are saved when the project is saved and also when the application is shut down. All macros are written into the /home/*USER*/.config/Ansys/optiSLang/calculator/macros.def file on Linux systems or the C:\Users\*USER*\AppData\Roaming\Ansys\optiSLang\calculator\macros.def file on Windows systems.

To use macros from other users, rename a copy of the other user's macros.def file and place it into the Ansys/optiSLang/calculator directory. When starting the application, or loading a project file, all files in the Ansys/optiSLang/calculator directory are scanned and all available macros are added to the Macros tab. If the macros are now saved (either by saving the project file or by shutting down the application) all macros in the Macros tab are only written into the macros.def file.