Using Parameters in Macros

Parameters are placeholders for information that you will provide when you actually execute a macro. You include parameters in the text of the commands to be executed by a macro. You write parameters as a "$" followed by the name of the parameter (the full format is explained below). You can include many different parameters, and you can include the same parameter more than once.
When you create a macro, Adams View scans the command text to identify all the parameters. When you issue the command to execute the macro, you provide values for the parameters, or they assume a default value. Adams View substitutes the values into the commands in place of the parameters, then executes the commands. If you used the same parameter more than once in the command text, Adams View substitutes the same value each place the parameter appears.

Example of a Macro with a Parameter

For example, the following macro shows how to change the size of all force and constraint icons in your modeling sessions. The command in the macro, named icon_size, contains a parameter named size:
constraint attributes constraint_name=.* size_of_icons = $size
force attributes force_name=.* size_of_icons = $size
When you enter the command:
icon_size size=1.5
Adams View executes the commands:
constraint attributes constraint_name=.* size_of_icons = 1.5
force attributes force_name=.* size_of_icons = 1.5

Expanding Parameter Values

In some cases, Adams View may reformat or expand parameter values before substituting them into the command text. Adams View never changes values, however. In particular, Adams View does not convert units during the macro substitution. It passes the values you enter directly to the commands. The commands themselves may convert units, as usual.
Adams View expands database names into full names before substituting them into the macros. The expanded names use "." to separate levels in the name. Using "." allows you to directly access database values in expressions.
For example, the following is a macro lpart that contains a parameter name:
list_info part part_name=$name
When you enter the following command:
lpart name=left_wheel
Adams View substitutes the full name of part left_wheel (for example, .mod1.left_wheel) for $name and executes the command:
list_info part part_name=.mod1.left_wheel

Generalized Parameter Format

The general format of a parameter is $'name:q1:q2:q3...', where:
name is the name of the parameter.
q1, q2, q3... are one or more qualifiers that specify the characteristics of the parameter.
The single quotes and qualifiers are optional (see below), giving four possible formats:
$name
$'name'
$name:q1:q2:q3...
$'name:q1:q2:q3...'

Parameter Naming Conventions

A parameter name must start with an alphabetic character. The rest of the name can include numeric characters and underscores ("_") as well as alphabetic characters (a-z, A-Z) but no spaces. The name ends at the first character that is not alphabetic, numeric, or an underscore. For more information, see Using Extended Names. Therefore, $P, $P1, and $PART_1 are valid parameter names while $PART#1 and $1P are invalid. Parameter names are not case sensitive, meaning $PART, $Part, and $part are all the same parameter.
You use single quotes to explicitly separate the name or qualifiers from command text immediately following the parameter. Normally, you place a space, comma, colon, or other special character after a parameter, which separates it from the following text. If you want to concatenate text to the end of a parameter, however, you must enclose the parameter name in single quotes. If, for example, you want to add "_1" onto the end of parameter $part, you cannot write $part_1, because Adams View would interpret it as a parameter named part_1. Instead, you must write $`part'_1.

Parameter Qualifiers and Formats

You can use qualifiers on the first occurrence of the parameter to control the parameter characteristics. Qualifiers are optional and can only be used the first time the parameter appears in the macro text.
Parameter can have one or more of the following qualifiers:
Type
You can use the qualifiers in any combination and any order, and you do not need to define all of them. If you repeat a qualifier, Adams View uses the last value. Qualifiers can be in upper or lowercase. Examples of qualifiers are:
 
Examples of Qualifiers
The qualifiers:
Specify that the parameter requires:
$parts:t=part:c=2
Names for two existing parts.
$NSpokes:T=INTEGER:GE=3:LE=8:D=3
An integer from 3 to 8 and a constant default of 3.
$infile:t=file(*.dat)
A file name. The File Selection dialog box lists all files with the extension .dat.

Type Qualifier

The type qualifier specifies the type of value a user must enter. The format for the type qualifier is:
T = type
T = type(additional data)
where:
type is a basic type, database object type, or database object class type as explained in the next sections.
Additional data is either optional or required depending on the type.

Range Qualifiers

A range qualifier specifies the minimum and/or maximum values allowed. It only applies to numeric types. The formats for the range qualifiers are listed in the table below.
 
Range Qualifier Formats
The format:
Specifies values must be:
GT=r
Greater than r
GE=r
Greater than or equal to r
LT=r
Less than r
LE=r
Less than or equal to r

Count Qualifiers

Count qualifiers specify the number of values required. The formats for the count qualifier are listed in the table below.
 
Count Qualifier Formats
The format:
Specifies:
C=0
One or more values
C=n
n values
C=n,0
n or more values
C=n,m
n to m values

Default Qualifiers

Default qualifiers are optional. If a parameter has no default, users must enter a value when executing the macro. There are three types of default qualifiers as well as a default value:
Constant - The parameter is optional. Adams View uses the default value if a user does not supply a parameter value.
Updated - The parameter is optional and Adams View uses the last value the user entered if the user does not supply a parameter value. If a user has not yet entered any value for a parameter, Adams View uses the default value.
Database object - The default for database objects is automatic. If the type is an existing database object, the automatic default is the current default object.
The table below lists the formats for the default qualifiers.
 
Default Qualifier Formats
The format:
Specifies:
D=value
Constant default
U=value
Updated default
A
Uses the default object for the specified type if no explicit value is given

Default Parameter Characteristics

The first occurrence of a parameter in the command text defines the parameter characteristics. This is true even if the first occurrence is in a comment. If the first occurrence includes qualifiers, the qualifiers determine the parameter characteristics. If there are no qualifiers and the parameter appears immediately after an "=" in a valid command, then the parameter inherits the type, range, count, and default from the preceding command parameter. If there are no qualifiers and the parameter does not appear immediately after an "=" in a valid command, the default characteristics are one string value with no default.
 
Tip:  
To avoid unexpected results, we recommend that you explicitly set the characteristics of your parameters in comments at the beginning of your macro. For examples of setting the characteristics in comments, see Example Macros.
In the example below, parameter $text defaults to a string because it has no qualifiers and is not in a command. Parameter $numbers has qualifiers that specify it as one or more integers greater than zero. Parameter $part_1 is a part because it immediately follows an "=" and, therefore, inherits the type from parameter part_name. Parameter $part_2 defaults to string because it does not immediately follow the "=". Parameters $part_3 and $part_4 have qualifiers that specify them both as parts.
! Parameter $text is a string.
! $numbers:t=integer:c=0:gt=0
list_info part part_name=$part_1, $part_2
list_info part part_name=$part_3:t=part, $part_4:t=part