optiSLang allows you to define macro expressions. Macro expressions create project placeholders composed of other user-defined placeholders or predefined constants. To define a macro expression:
In the project placeholders table, double-click the Value cell of the placeholder.
Select the
check box.Enter the macro expression in the text field to the right of the check box, or click
( ) to open a separate dialog box with a larger text field.
Project placeholders are type-specific. A placeholder can be assigned to a project property only if they share the same data type. The macro language slightly differs between the types, but all types share the same rules for placeholder substitution, text concatenation, and literal escaping.
General Syntax
Placeholder Substitution
The syntax for placeholder substitution is $(placeholder_id)
. For
example, to use the placeholder pl1 in a macro expression, the expression must
contain $(pl1)
. This entry is substituted by the value of pl1 by the
placeholder engine. Multiple placeholder substitutions can be used in a macro
expression and a placeholder can be used multiple times.
The exception to this rule are numeric types. You do not need to add $ or enclosing parenthesis.
Text Concatenation
Text can be concatenated by appending text. No separators or operators are needed.
For example, you have two placeholders pl1 and pl2 of type string
with
the values S and L respectively. The macro
expression for creating the string optiSLang
in this case is:
opti$(pl1)$(pl2)ang.
Literal escaping
Since the $
literal is used as a language literal, it must be escaped
in case it is used as a plain string. The syntax for escaping is
\
.
Type-specific Syntax
String
String types require no specific syntax. The general syntax rules apply.
Example:
Placeholders: pl1 := S; pl2 := L Expression: opti$(pl1)$(pl2)ang Result: optiSLang
Path
Path types support a specific, platform-independent, separator literal for
separating path entries. The path separator is /
. The syntax rules for
strings also apply.
Example:
Placeholders: model := ten_bar_truss Expression: C:/samples_path/$(model)/$(model).s Result: C:/samples_path/ten_bar_truss/ten_bar_truss.s
Split Path
Split path types support a specific literal for the path splitting position. The
path splitting literal is |
. The syntax rules for plain paths also
apply.
Example:
Placeholders: model := ten_bar_truss Expression: C:/samples_path/$(model)|$(model).s Result: C:/samples_path/ten_bar_truss/ten_bar_truss.s (Head: C:/samples_path/ten_bar_truss; Tail: ten_bar_truss.s)
Relative Split Path
Relative split path types support a specific prefix for defining the mode of relative split path. This prefix can be one of the following:
ABS: The path is considered to be absolute.
WD_REL: The split path tail is considered to be relative to the working directory.
PROJ_REL: The split path tail is considered to be relative to the project.
The prefix must be followed by a ;
and a path or split path. The
syntax rules for plain and split paths also apply.
Example:
Placeholders: model := ten_bar_truss Expression: WD_REL;C:/samples_path/$(model)|$(model).s Result: C:/samples_path/ten_bar_truss/ten_bar_truss.s (Head: C:/samples_path/ten_bar_truss; Tail: ten_bar_truss.s; ten_bar_truss.s considered to be relative to working dir)
String List
String list types support a specific separator literal for separating string
entries. The string list entry separator is ;
. The syntax rules for
strings also apply.
Example:
Placeholders: pl1 := hello; pl2 := world Expression: $(pl1);$(pl2);. Result: String list with 3 entries [hello; world; .]
Numeric Types
The numeric types (Boolean, Integer, Unsigned integer, Real) support the optiSLang calculator expression syntax and their predefined objects and constants. For more information, see Using the Calculator.
Example:
Placeholders: pl1 := 2; pl2 := 1.5 Expression: sin(pl1) + pl2 Result: 2.4093
Predefined Constants
The placeholder macro language contains predefined constants that can be used in macro expressions. The syntax rules for placeholder substitutions apply. The constants are:
PROJECT_DIR: location of the current optiSLang project
For numeric types, you can use the constants defined by the optiSLang calculator. For more information, see Using the Calculator.
Auto Completion
The placeholder macro expression line and text edits support auto completion for available placeholders and predefined constants. To use this feature, press Ctrl+Space to display the suggested placeholder names. Alternatively, you can start typing and the suggestions are automatically displayed when at least two characters of an available placeholder name have been typed.