Basic Commands (Template Language)

Basic commands of Software Ideas Modeler template language.
Command Result Type Description
IsLastItem Boolean

Returns true if the current item in the enumeration is the last one. No parameters are needed.

Example: Within a loop, IsLastItem can be used to determine if the loop has reached the last element.

IsFirstItem Boolean

Returns true if the current item in the enumeration is the first one. No parameters are needed.

Example: Within a loop, IsFirstItem can be used to check if the loop is at the first element.

NotifyProgress(progress:Number) Void

Reports the template processing progress, where progress is a value from 0 to 1, with 1 indicating completed processing.

Parameter: A number indicating the current progress.

Example: NotifyProgress(0.5) reports that the processing is halfway done.

Range([from:Number], to:Number) Array

Returns an array of numbers from 0 or the "from" parameter to the "to" parameter.

Parameters: An optional starting number (default is 0) and an ending number.

Example: Range(1, 3) returns [1, 2, 3].

Switch(case:Object, statement1:Object, return1:Object, ..., statementN:Object, returnN:Object) Object

Returns the returnI value if the case object equals the statementI object.

Parameters: A case object to compare against, followed by pairs of statements and their corresponding return values.

Example: Switch("b", "a", 1, "b", 2) returns 2 because the case "b" matches the second statement.

Now String

Returns a string with the current date and time. No parameters are needed.

Example: Now might return "2024-03-12 14:45:00".

Today String

Returns a string with the current date without time. No parameters are needed.

Example: Today might return "2024-03-12".

ResetCounter([counterName:String]) Void

Sets the specified counter to zero. If no counter name is provided, the default counter is reset.

Parameter: An optional name of the counter to reset.

Example: ResetCounter("myCounter") resets "myCounter" to zero.

AddToCounterReserved(reservedNumber:Number, [counterName:String]) Void

Excludes a reserved number from a counter. This number will be skipped in subsequent uses of the counter.

Parameters: The number to reserve and an optional name of the counter.

Example: AddToCounterReserved(5, "myCounter") reserves the number 5 in "myCounter".

GetNextFreeNumber([counterName:String]) Number

Returns the next free number for the specified counter, skipping any reserved numbers. If no counter name is provided, it uses the default counter.

Parameter: An optional name of the counter.

Example: GetNextFreeNumber("myCounter") might return 6 if 5 is reserved and 4 is the last used number.

HasImports Boolean

Returns true if there are imports (usings, imported packages) defined for the generation. No parameters are needed.

Imports Enumerator

Enumerates top-level imports defined for the current code generation. This is used within a loop to process each import.

Usage context: <%==SIM:ForEach:Imports==%> to iterate over each import and <%==SIM:Import.Name==%> within the loop to get the name of the import.

CreateDocumentContext Object

Creates and returns a new document context. This context can be used to build a formatted text document. No parameters are needed.

ExplicitWhitespacesOn Void

Activates explicit whitespace mode, which removes all automatic whitespaces, including line breaks, from the template output. Whitespaces must be manually added using the Space, Tab, and Line commands.

ExplicitWhitespacesOff Void

Deactivates explicit whitespace mode, allowing the template engine to manage whitespaces automatically.

ExplicitLinesOn Void

Prevents line breaks present in the template text from being transferred to the output, requiring explicit use of the Line command to insert line breaks.

ExplicitLinesOff Void

Allows line breaks in the template to automatically appear in the output, without needing to use the Line command.

CompactOn Void

Activates compact mode, which removes only trailing line breaks after commands from the output, making the generated content more compact.

CompactOff Void

Deactivates compact mode, allowing trailing line breaks after commands to be included in the output.

IndentSize(value:Number) Void

Sets the default indentation size for the processing session. This size is used by the Indent and StartBlock commands to determine the level of indentation.

Parameter: A number specifying the number of characters to use for each indentation level.

SetSpaceIndent Void

Sets space characters as the indentation character for the current document context.

SetTabIndent Void

Sets tab characters as the indentation character for the current document context.

AutoIndentOn Void

Enables automatic indentation, adding leading whitespaces for new lines based on the current indentation level, which is managed by StartBlock and EndBlock commands.

AutoIndentOff Void

Disables automatic indentation, preventing the addition of leading whitespaces for new lines.

StartBlock Void

Increases the current nesting (indentation) level by one, affecting subsequent lines until EndBlock is called.

EndBlock Void

Decreases the current nesting (indentation) level by one, returning to the previous indentation state.

Space([number:Number]) Void

Adds a specified number of space characters to the output. If no number is provided, adds a single space.

Parameter: An optional number of spaces to add.

Indent(level:Number) Void

Adds indentation to the output based on the current settings (character and size) multiplied by the specified level.

Parameter: The level of indentation to add, with each level corresponding to the indent size set by IndentSize.

IncreaseAutoIndentBase(value:Number) Void

Temporarily increases the base indentation level by the specified value, affecting the indentation of lines generated by the Line command.

Parameter: The value by which to increase the base indentation level.

DecreaseAutoIndentBase(value:Number) Void

Temporarily decreases the base indentation level by the specified value, affecting the indentation of lines generated by the Line command.

Parameter: The value by which to decrease the base indentation level.

WithoutStereotypes Filter

Returns a filter used to exclude elements with any stereotypes in commands that support filtering, such as RelatedElements.

Tab([number:Number]) Void

Adds a tab or the specified number of tabs to the output.

Parameter: An optional number of tabs to add.

Line([number:Number]) Void

Adds a line break or the specified number of line breaks to the output.

Parameter: An optional number of line breaks to add.

GetModel(element:Element) Object

Returns the model of the specified input element, allowing access to its properties and relationships.

Parameter: The element whose model is to be retrieved.

Coalesce(p1:Object, p2:Object, ... pn:Object) Object

Returns the first non-empty and non-null object among the given parameters. This command is useful for selecting the first available value when multiple potential values are present.

Parameters: A list of objects to evaluate in order.

Example: Coalesce(null, "", "firstNonNull", "secondNonNull") returns "firstNonNull" as it is the first non-null and non-empty object.

New Comment

Comment