%for keyword (SDL script)
The %for keyword starts a For loop, which iterates through a collection of items that are linked to the current item through a specific link type, or iterates through a list.
For more information about For loops, see For loop (SDL script).
The current item is derived as follows:
ACS calls the top-level Generate.sdl generation template for each item (Model, Package or Class) that is selected either directly or indirectly for generation. On entering the Generate.sdl generation template, the selected Model, Package or Class is the current item.
The current item remains as the selected Model, Package or Class until a For loop iterates a collection of linked items or items in a list. During a For loop, the current item is the item that is currently being iterated.
After leaving a For loop, the current item reverts to the item that was the current item before entering the For loop.
Syntax
For a collection of items:
%for "<link type>" [%separator "<separator characters>"]
<set of statements>
[%exit]
%endfor
For a global list:
%for %getlist "<list name>" [%separator "<separator characters>"]
<set of statements>
[%exit]
%endfor
For a local list:
%for %getlocallist "<list name>" [%separator "<separator characters>"]
<set of statements>
[%exit]
%endfor
The <link type> is the automation interface name of the link type that links the current item to other items. For more information about the automation interface names of link types, see Object Attributes and associations under the Automation Interface chapter of the PTC Modeler Help, and then click the required item type. The link types are listed in the Associations section.
The following examples are provided:
For loop processing linked items
For loop processing list
Example 5. For loop processing linked items
This example works in the context of an Operation and uses the 'Parameter' automation interface association to process the Operation's Parameters. For each Parameter, it loads the Parameter.sdl template.
%for "Parameter"
%load "Parameter.sdl"
%endfor
Example 5. For loop processing list
This example runs a set of statements against each item in the 'IncludedObjects' list.
%for %getlist "IncludedObjects"
$ calculate and output the #include
%if %inlist "sysCurrentObject" %then
$ self so don't include
%else
%load "OutputInclude.sdl"
%setlocalvar "nGeneratedDependency" = 1
%endif
%endfor
Was this helpful?