for
The FOR and END commands allow you to execute a group of commands a fixed set of times. You can use FOR either to perform numeric iteration or to operate on a set of Adams View objects, such as markers or parts. Adams View executes the commands bracketed by FOR and END for each value of a variable in the specified range or upon the specified set of objects.
You can nest any combination of looping (FOR/END, WHILE/END) and conditional constructs (IF/ELSEIF/ELSE/END).
Format:
for |
|---|
variable_name = | variable |
object_name = | existing object |
start_value = | real |
end_value = | real |
type_filter = | object_type |
group_name = | existing group |
echo_all_loops = | yes/no |
end | |
Example:
for variable_name=tempreal start_value=1 end_value=10
marker create marker_name=(eval("MAR" // RTOI(tempreal))) &
location=(eval(tempreal-1)), 0, 0
end
In this example, Adams View creates 10 markers, MAR1 through MAR10, on the default part, and locates them one unit apart on the x-axis of the part's coordinate system.
Description:
Parameter | Value Type | Description |
|---|
variable_name | New Variable | Specifies the name of the temporary variable to be created within the loop |
object_names | Existing Object | Specifies an existing object. This is used when FOR is to be operated on a set of objects. |
type_filter | Object Type | The TYPE parameter applies a filter to the set of objects. |
start_value | Real Expression | Specifies the starting value of the variable in the loop. |
end_value | Real Expression | Specifies the last value of the variable in the loop. Once the loop is executed for this value, it terminates. |
increment_value | Real Expression | Specifies the increment for the value of the variable for each iteration in the loop. This can be either positive or negative. |
group_name | Existing Group | Specifies a group name |
echo_all_loops | Yes/No | Specifies a Boolean value |
Extended Definition:
1. When the FOR statement is operated on objects, the object_name parameter is used.
FOR VARIABLE_NAME=var OBJECT_NAMES=objects &
TYPE=database_object_type
...
END
For this type of FOR loop, Adams View creates a temporary Adams View variable named var of type OBJECT and successively assigns the value of each object in the set to the variable. The commands inside the FOR/END pair can use var as they would any other Adams View variable of type OBJECT. Adams View deletes the variable when the loop terminates.
2. Consider the following example in which Adams View renumbers the Adams IDs of markers belonging to the part follower, starting at 5000, and incrementing by one for each marker in the set.
variable create variable_name=ip integer_value=5000
for variable_name=the_marker object_names=.fourbar.follower.* type=marker
marker modify marker_name=(eval(the_marker)) adams_id=(eval(ip))
variable modify variable_name=ip integer_value=(eval(ip+1))
end
variable delete variable_name=ip
You can use the EVAL function to get the instantaneous value of an expression rather than assigning the expression itself. An expression's value changes whenever the value of any variable in it changes. Sometimes you want this behavior; other times you do not. Using EVAL avoids this behavior.
As shown, you can use wildcards to specify the objects for the OBJECT_NAME parameter. The TYPE parameter applies a filter to the set of objects, in this case, matching only children of the part that are markers.
If you use a more general wildcard, Adams View may execute the command more slowly than if you use a more specific wildcard. For example, if you want all the markers in the model MOD1, use OBJECT_NAME=.MOD1.* type=MARKER instead of OBJECT_NAME=* type=MARKER.