Professional Documents
Culture Documents
You can customize Adams/View so that it works and looks the way you want it to and mimics your design
environment. There are four major ways to customize it. You can:
• Customize the graphical interface - For example, you can create your own set of menus or
dialog boxes.
• Automate your work using macros - You can also speed up your work by creating macros to
perform complex or repetitive tasks. You can edit the macros to include design variables to
further customize and automate the modeling process.
• Create your own Adams/View library - The library you create can read in different
Adams/View functions and execute commands. For information on creating libraries, refer to
Running and Configuring Adams.
• Edit Adams/View startup files - You can edit the files that Adams/View reads when it first
starts. These files can automatically load a model, execute commands, or change menus or
dialog boxes. For information on editing startup files, refer to the Running and Configuring
Adams.
To make it easy for you to create a macro, Adams/View contains tools to automate the creation of macros.
The tools let you interactively record, play, and test your macros and command files. You can also use
text-editing applications to modify existing macros or create them from scratch.
• Using the Command Navigator or Command window to type in the commands to create macros
as well as the commands to be executed. Learn about using the Command Navigator and
Command Window.
Recording a macro is easiest for simple macros, while reading in a file is best for more complex macros.
When you read in a file, you can also specify the help file or string that you want associated with the
macro. Using the Macro Editor is best for editing existing macros. If you use the Macro Editor to create
macros, you must type in the commands that the macro is to execute.
3. If you are creating a macro, in the Macro Name text box, enter the name of the macro.
4 Adams/View
About Adams/View Macros
4. In the Command text box, enter the command string that executes the macro. To use the name of
the macro, select Use Macro Name.
Note: The command string you enter must be unique. You cannot redefine an existing command,
although you can add a new keyword at any level to an existing command. For instance,
entering MARKER CREATE is invalid, because a MARKER CREATE command already
exists, but entering MARKER GENERATE is valid.
5. Specify whether or not the entire macro can be undone with a single Undo command. Note that a
single Undo=yes, while convenient, can consume a great deal of memory for very large macros,
or slow macro execution noticeably, even if you do not ever use the Undo. You might want to
specify Undo=yes during initial creation and debugging until your macro works properly, then
switch to Undo=no to improve performance.
6. In the Commands text area, enter the commands that the macro is to execute, and select OK.
Recording Macros
Recording a Macro is easiest for simple macros.
To record a macro:
1. From the Tools menu, point to Macro, point to Record/Replay, and then select Record Start.
2. Perform the operations you want included in the macro.
3. To stop recording the macro, from the Tools menu, point to Macro, point to Record/Replay, and
then select Record Stop.
The file you supply that contains the macro definition is a command file that can also contain parameters
embedded in the commands and can have special comments at the top.
Some of the comments in the file you supply can correspond to Read command parameters that are listed
in the Macro Read dialog box, such as the command users enter to execute the macro. These comments
must appear at the beginning of the file and must contain the name of one of the reserved parameters
(USER_ENTERED_COMMAND, WRAP_IN_UNDO, HELP_STRING, or HELP_FILE) followed by
an appropriate value.
These reserved parameters must be in uppercase letters and must immediately follow the comment
character (!). You enter the values without equal signs or quotes. Adams/View treats the values in the
comments as defaults. For example, the following comments set the default values for
USER_ENTERED_COMMAND and HELP_STRING.
!USER_ENTERED_COMMAND lmark
!HELP_STRING This command lists information on all markers in your database.
list_info marker marker_name=.*
If you specify values for these parameters using the Macro Read dialog box, the values in the dialog box
override the values in the comments.
Note: The Macro Read dialog box contains an option to create a panel. This option is no
longer supported or recommended.
2. In the Macro Name text box, enter the name of the macro that Adams/View uses to store the
macro in the current database.
3. In the File Name text box, enter the name of the file containing the commands to be executed.
4. In the User Entered Command text box, specify the command string that will execute the macro.
The command string defaults to the name of the macro if you do not enter a command string.
5. Specify whether or not the entire macro can be undone with a single Undo command. Note that
a single Undo, while convenient, can consume a great deal of memory for very large macros or
slow macro execution noticeably, even if you do not actually use the Undo.
6. Specify a text file containing help on the macro or enter a text string describing the macro.
Currently, you can only specify help for the entire macro command, not its parameters or leading
keywords.
7. To ensure that you do not create an outdated dialog box, from the Create Panel option menu,
select no.
6 Adams/View
About Adams/View Macros
8. Select OK.
Note: To create an up-to-date dialog box to execute your macro, go to the Command
Navigator and double-click on the name of your macro after you have created it.
Adams/View automatically creates a dialog box whose name is based on the user-
entered commands associated with the macro. For example, if you create a macro
called mar_scale_down and associated with it the user-entered commands: marker
scale down, then Adams/View names the auto-generated dialog box
.gui.mar_sca_dow (Adams/View uses the first three characters of each command in
the user-entered commands to create the name of the dialog box). See also
Customizing Dialog Boxes Using the Dialog-Box Builder, and the example.
Saving Macros
Adams/View automatically stores your macros in the current modeling session. You can also export your
macros to command (.cmd) files, which allows you to edit, archive, or import them into other modeling
session. It also lets you give the macro to another user, and also helps you to modify long macros when
you do not have the original file
If you used non-default values for the other macro data, such as the help string, the command file includes
comments with those values. You can read in the command file using the Macro Read command.
Deleting Macros
To delete objects using the Database Navigator:
1. Clear the select list of any existing selections by selecting the Select Tool .
2. On the Edit menu, select Delete.
The Database Navigator appears.
3. Select the macro or macros that you want to delete. Learn about navigating through a modeling
database using the Database Navigator.
Automating Your Work Using Macros 7
About Adams/View Macros
4. Select OK.
Note: If the Database Navigator does not appear as indicated in Step 2, the select list was
not cleared before executing the Delete command. You can always use the Edit ->
Select List commands to be sure it is cleared.
Debugging Macros
Adams/View provides a debugging tool to help you troubleshoot your macros if they don't run or work
as expected. You can use the debugging tool to:
• View your macro and the output from it.
• Step through each command in the macro.
• Print your macro.
Executing Macros
Once you have created a macro, you execute it by issuing the command that you specified when you
created the macro. You can issue the command by:
• Entering the command in the Command window. The full command is a combination of the
command and macro parameters, if any.
• Using the Command Navigator to execute the command. Selecting the macro command in the
Command Navigator, automatically displays a dialog box in which to enter parameters.
• Using a custom dialog box and menu command that you created to execute the macro. Learn
more about Customizing Dialog Boxes Using the Dialog-Box Builder.
Adams/View treats the macro as it does other Adams/View commands. For example, if you enter the
command in the command window, but do not enter all required parameters, Adams/View prompts you
for the missing required parameters.
It can also be slow and distracting, however, once your macro is working properly. You can prevent this
by including the following as the first command in the macro:
defaults command_file echo=off update=off
Including the command allows macros to run more quickly because Adams/View does not echo the
macro commands to the command information area and updates the views only once, when the macro is
finished. You can reset the defaults by including the following command as the last line in your macro:
defaults command_file echo=on update=on
If you execute a macro from a dialog box or menu, Adams/View, by default, updates the screen at each
change, but does not echo the macro commands to the command information area.
For example, you can use an IF command to conditionally execute commands within your macro. You
can create a parameter to specify a choice of options, then use the IF statement to determine which option
was chosen and execute the appropriate commands.
For more information on the different conditional constructs, see Conditional Constructs and Loops.
By including the System command, you can create macros that invoke outside utilities and programs.
You could, for example, create a macro that generates hardcopy files for a standard series of plots, then
use the System command to issue comments to print and delete the plots.
The single quotes and qualifiers are optional (see below), giving four possible formats:
• $name
• $'name'
• $name:q1:q2:q3...
• $'name:q1:q2:q3...'
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.
Count Qualifiers
Count qualifiers specify the number of values required. The formats for the count qualifier are listed in
the table below.
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.
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
Automating Your Work Using Macros 15
Helpful Commands in Macros
Tip: For more help on using commands, see the online help available from the Command
Navigator. Simply select a command and then select the Help button at the bottom
of the Command Navigator.
You can specify to write to a file, a variable, both, or neither. If writing to a file, you must open it first
using the file text open command.
If you specify:
• Just the file_name, Adams/View writes the output to that file.
• Just the variable_name, Adams/View assigns the text string to that variable.
• Both file_name and variable_name, Adams/View performs both actions.
• Neither, Adams/View assumes the last opened, written, or read file is the intended destination. If
you perform a write after a read, you should explicitly identify the file with the file_name
parameter, so Adams/View does not overwrite the file you last read from.
16 Adams/View
Helpful Commands in Macros
Parameters
file_name Specifies the name of the text file to be written. The proper extension is the
(optional) default, but you can be override it by supplying a different extension.
It's not necessary to enclose the file name in quotes if it only contains alpha-
numeric characters and starts with a letter. If you want to include other
characters, such as a '.' for an extension or '/' or '[]' for directory paths, you
must enclose the name in quotes.
variable_name Specifies a variable to which Adams/View stores a formatted string.
(optional)
format_for_output Specifies the format of the output text. Output formats are a mixture of text
(required) and conversion specifications. Each conversion specification usually has a
matching argument in the values_for_output parameter. A conversion
specification begins with a percent sign, %, and is terminated by a letter or
another percent sign.
Most conversion specifications can contain flags between the leading percent
sign and the terminating conversion specifier. These flags allow you to further
refine the format of your output. Some of the valid flags are:
- Indicates that the output is to be left justified in the field, with the default
being right justification. This is only useful when the field width is specified
(see below).
"005.....7"
You specify precision by entering a decimal point followed by a number. You
enter the precision after the field width. For example:
You can write information from the Adams/View database to the text file by
using data access references in the value expressions. For example,
VALUES= (.mod1.par1.mass) writes the mass of part par1. For more
information on expressions and database access, see Adams/View Function
Builder online help.
18 Adams/View
Helpful Commands in Macros
system
Issues a device-dependent operating system command. You can select to display the results of the
command in the Information Window or the Adams/View Log file.
Parameters
Examples
The following example issues a UNIX-appropriate command to remove the file named test.txt without
displaying the command in either the Adams/View Information window or a log file:
SYSTEM COMMAND="rm test.txt" SEND=OFF ECHO=OFF
Automating Your Work Using Macros 19
Conditional Constructs and Loops
BREAK
Use the BREAK command to exit the innermost FOR or WHILE loop immediately and stop execution
of the loop.
When Adams/View encounters a BREAK command inside a loop, it immediately exits the loop without
executing the remaining commands for that iteration.
The BREAK command affects only the innermost FOR or WHILE loop.
Format
BREAK
Example
In this example, Adams/View creates markers, named MAR1, MAR2, MAR3, MAR4, and MAR5,
unless a marker already exists with one of those names. As soon as it encounters an existing marker,
Adams/View exits the loop and does not create any more.
variable create variable_name=ip integer_value=0
while condition=(ip < 5)
variable modify variable_name=ip integer_value(eval(ip+1))
if condition=(eval(DB_EXISTS ("MAR"//ip)))
break
end
marker create marker_name=(eval("MAR"//ip)) &
location=(eval(ip-1)),0,0
end
variable delete variable_name=ip
CONTINUE
Use the CONTINUE command to skip commands inside the innermost FOR or WHILE loop and
continue with the next iteration of the loop.
When Adams/View encounters a CONTINUE command inside of a loop, it skips over the remaining
commands of the loop and goes directly to the END of the innermost loop. Adams/View tests the loop
condition and continues looping if the condition is still valid.
The CONTINUE command affects only the innermost FOR or WHILE loop.
Format
CONTINUE
20 Adams/View
Conditional Constructs and Loops
Example
In this example Adams/View creates four markers on the default part: MAR1, MAR2, MAR4, and
MAR5. Adams/View skips MAR3, because when ip evaluates to 3, Adams/View encounters the
CONTINUE command and skips to the END of the WHILE loop.
variable create variable_name=ip integer_value=0
while condition=(ip < 5)
variable modify variable_name=ip integer_value=(eval(ip+1))
if condition=(ip == 3)
continue
end
marker create marker_name=(eval("MAR"//ip)) &
location=(eval(ip-1)),0,0
end
variable delete variable_name=ip
The results of the example would be:
IF/ELSEIF/ELSE/END
Use the IF, ELSE, ELSEIF, and END commands to execute a group of commands conditionally. The
execution of commands bracketed by IF and END depends on the value of an expression.
You can nest any combination of looping (FOR/END, WHILE/END) and conditional constructs
(IF/ELSEIF/ELSE/END).
Note: As with all Adams/View commands, you can use the IF, ELSE, ELSEIF, and END
commands on the command line, in macros, and in command files.
Format
You can use the IF command with or without the ELSE command. A few examples of many variations
are shown below.
IF CONDITION=(expression)
...
END
IF CONDITION=(expression)
...
ELSE
...
END
IF CONDITION=(expression)
...
ELSEIF CONDITION=(expression)
...
ELSE
...
END
If the expression evaluates to a non-zero value, Adams/View executes the commands following the IF or
ELSEIF command up to the ELSE, when present, or the END if you do not use the ELSE. If the
expression evaluates to zero and you used ELSE, Adams/View executes the commands between the
ELSE and the END commands.
The question-mark/colon (?:) operator used in a conditional expression replaces and IF/ELSE command
that distinguishes one of two values. The expression consists of three parts, a condition whose truth
determines which value is selected, and two expressions for the values.
condition expression ? expression a : expression b
When evaluated, the conditional takes on one of the two values. The expression that comes before the
question-mark is interpreted as boolean-valued. If it is true (non-zero), then expression a is used as the
value of the conditional, otherwise expression b is used as the value.
For example, consider the commands below:
if condition = (variable_a < variable_b) variable set variable =
variable_min real = (EVAL(variable_a)) else variable set
variable = variable_min real = (EVAL(variable_b)) end
This can be expressed more concisely by using a ?: conditional operator:
variable set variable = variable_min & real = (EVAL((variable_a <
variable_b)? variable_a : variable_b))
Example
In the following example, if the marker MAR1 exists, Adams/View modifies its location. If the marker
does not exist, Adams/View creates it and sets its location.
if condition=(DB_EXISTS ("MAR1"))
marker modify marker=mar1 location=2,0,0
else
marker create marker=mar1 location=2,0,0
end
22 Adams/View
Conditional Constructs and Loops
The next example illustrates how to use ELSEIF to determine the type of object and then perform an
operation on the object based on the object's type. The example assumes that an Adams/View variable
named .mdi.org exists and its type is database object.
! Bodies
variable create variable=object_type string=(eval(DB_TYPE(.MDI.obj)))
if condition=(object_type == "marker")
interface command_builder command="marker modify marker" initial=(.MDI.obj)
elseif condition=(object_type == "point")
interface dialog display dialog=.gui.main_objecttable parameter="Points"
elseif condition=(object_type == "flexible_body")
interface dialog display dialog=.gui.flx_dia_panel parameter=(.MDI.obj)
! Constraints - complex joints
elseif condition=(object_type == "coupler" )
interface dialog display dialog=.gui.coupler_cremod parameter=(.MDI.obj)
elseif condition=(object_type == "gear" )
interface command_builder command="constraint modify complex_joint gear"
initial=(.MDI.obj)
! Constraints - Higher Pair contact
elseif condition=(object_type == "curve_curve" )
interface command_builder command="constraint modify higher_pair_contact
curve_curve" init=(.MDI.obj)
elseif condition=(object_type == "point_curve" )
interface command_builder command="constraint modify higher_pair_contact
point_curve" init=(.MDI.obj)
end
FOR/END
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 the 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
warning message and does not delete the variable at the termination of the loop. If you do not want this
behavior, you can use the EVAL function as described in Examples of Numeric Iteration for FOR/END.
START_VALUE, INCREMENT_VALUE, and END_VALUE can be any valid real expression.
INCREMENT_VALUE can be either positive or negative, and defaults to 1.0 if not specified. If
INCREMENT_VALUE is positive, Adams/View increments the value of var by the increment for each
iteration and stops looping when the value of var is greater than END_VALUE.
If INCREMENT_VALUE is negative, Adams/View decrements var by the increment for each iteration
and continues looping until var is less than END_VALUE.
The commands inside the FOR/END loop can use var as they would any other Adams/View variable of
type REAL.
In this example 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
As in the previous example, you can use the EVAL function to get the instantaneous value of an
expression rather than assigning the expression itself.
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.
For more sophisticated searching and filtering, see the database functions, such as DB_CHILDREN, in
the Design-Time Functions section of the Adams/View Function Builder online help. You also may want
to use the miscellaneous function SELECT_OBJECT of the same guide.
WHILE/END
Use the WHILE and END commands to execute a group of commands zero or more times. Adams/View
executes the commands that WHILE and END bracket repeatedly until the condition associated with the
WHILE command is FALSE (zero).
You can nest any combination of looping (FOR/END, WHILE/END) and conditional constructs
(IF/ELSE/ELSEIF/END).
Format
The format of the WHILE command is:
WHILE CONDITION=(expression)
...
END
Adams/View evaluates the value of expression and executes the commands between the WHILE and the
END command if the value is non-zero. Adams/View evaluates the expression at the end of the loop and
continues looping as long as the value of the expression is non-zero.
Automating Your Work Using Macros 25
Conditional Constructs and Loops
Examples
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 coordinate system.
variable create variable_name=ip integer_value=0
while condition=(ip < 10)
marker create marker_name=(eval("MAR"//ip+1)) &
location=(eval(ip)),0,0
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 value of an expression rather than assigning the expression
itself. Use of the EVAL function with loops is described in the FOR/END.
RETURN
Use the RETURN command to exit a command file or macro and return to the command file or macro
that invoked it. Its effect is similar to BREAK when you use it to exit a loop, skipping all remaining
commands in the command file or macro (including any cleanup commands you may have at the end of
your macro).
If a RETURN is executed within loops (nested to any depth), it exits those loops and performs all required
cleanup, just as multiple BREAKs would do. You can have as many RETURN commands in your
command files or macros as you want.
Format
RETURN
Example
RETURN is often used as a means for recovering from an error condition or allowing a user to cancel an
operation. Below are two examples.
Example 1
In the example, the RETURN command lists information on the contents of the select list, but only if
there are objects on the list. If it finds no objects, it returns and issues an error message.
if condition=(DB_COUNT(.SELECT_LIST, "objects_in_group")==0)
mdi gui_utl_alert_box_1 type="Error" text="Select List is
empty. Select objects first."
return
end !if
!
info empty
!
list_info group &
group_name = .SELECT_LIST &
brief = on &
26 Adams/View
Conditional Constructs and Loops
write_to_terminal = on
!
Example 2
This example macro determines if a particular file exists and asks the user if it should overwrite the
existing file.
variable create variable=$_self.fileName string="file.dat"
if condition=(file_exists($_self.fileName))
if condition=(alert("warning", "Delete existing
"//$_self.fileName//"?", "Ok", "Cancel", "", 2) == 2)
variable create variable=$_self.junk &
int=(alert("information", "File "//$_self.fileName//" not
destroyed.", "Ok", "", "", 1))
variable delete variable=$_self.*
return
end
! Clean up.
variable delete variable=$_self.*
Format
condition expression ? expression a : expression b
When evaluated, the conditional takes on one of the two values. The expression that comes before the
question mark is interpreted as Boolean-valued. If it is true (nonzero), then expression a is used as the
value of the conditional, otherwise expression b is used as the value.
Example
For example, consider the commands below:
if condition = (variable_a < variable_b)
variable set variable = variable_min real = (EVAL(variable_a))
else
variable set variable = variable_min real = (EVAL(variable_b))
end
Interface 27
Conditional Constructs and Loops
You can express this more concisely using the ternary conditional operator:
variable set variable = variable_min &
real = (EVAL((variable_a < variable_b)? variable_a : variable_b))
Note: The ternary conditional operator has lower precedence than all other operators. Any
operations performed in sub expressions are performed before the ternary operator is
evaluated:
x < 10 ? x + 10 : x * 10
is the same as:
(x < 10) ? (x + 10) : (x * 10)
Likewise:
s == "Bob" ? "Hello" : "Goodbye" // ", " // s
is evaluated as:
(s == "Bob") ? ("Hello") : ("Goodbye" // ", " // s)
Interface
28 Adams/View
About Adams/View Menus and Dialog Boxes
Note: You cannot customize all Adams/View dialog boxes and tools. For example, you cannot
customize the Plugin Manager or the Information window. The Dialog-Box Builder's
Dialog Box -> Open menu provides access to those dialog boxes, containers, and toolbars
that you can customize.
• Dialog-Box Builder
• Command Navigator
• Data Browser in the plotting window
• File Selection dialog box
• Coordinate window
• Plugin Manager
When you create menus in Adams/View, you can specify keyboard accelerators (shortcuts) and
mnemonics.
There are four types of objects in menus: menus, push buttons or icon buttons, toggle buttons, and
separators. The text lines that define these are shown in the table below. Click a text line to learn more.
MENU
A MENU entry creates a pull-down or pull-right menu. First-level menus, MENU1, appear in the menu
bar and pull downward. Lower-level menus, such as MENU2 and MENU3, appear as cascading pull-
right menus.
Syntax
MENUn TITLE
NAME=name
HELP=Help
Parameters
• n = Number identifying whether the menu appears on the menu bar or on a pull-down menu. Can
be either:
• n = 1 - Menu appears on menu bar.
• n 2 - Menu appears on pull-down menus.
• TITLE = Text string that appears in the menu bar. You can also place an & in the title in front of
the letter to be used as the keyboard mnemonic (for example, enter &File to have the resulting
menu be File and the mnemonic would be Alt+F).
• NAME = Name of the object in the modeling database. If you omit NAME, Adams/View
constructs a default identifier, such as MENU_4 or BUTTON_7.
36 Adams/View
Customizing Menus Using the Menu Builder
• HELP = Text that appears in the status bar and in the tool tips, and describes the menu group.
Example
MENU1 File
NAME=file
HELP=Read and write files
Syntax
BUTTONn LABEL :: ACCELERATOR
NAME=name
HELP=help
CMD=command
Parameters
• n = Number identifying the placement of the button. Can be either:
• n = 2 - Button appears on pull-down menu.
• n = 3 - Button appears on a sub-menu.
• LABEL = Button name that appears in the pull-down or sub-menu. By convention, you should
include ellipsis (...) after the button name if the button displays a dialog box. You can also place
an & in the label in front of the letter to be used as the keyboard mnemonic (for example, enter
&Save to have the resulting menu command be Save and its mnemonic be Alt+S.)
• ACCELERATOR = Key or series of keys that execute the menu command. To create a series of
keys, you use the Shift, Ctrl, or Alt keys followed by the plus symbol (+) and any letter (a to z)
or function key (F1, F2, and so on). No spaces can be between any of the keys (for example,
Alt+A, instead of Alt + A).
The Shift, Ctrl, and Alt keys are case sensitive (the first letter must be capitalized), while the
key letters are not (user can enter A or a). You also can group the Shift key with the Ctrl and Alt
keys (for example, Shift+Ctrl+A). If you combine the keys, the Shift key must be executed first.
• NAME = Name of the menu object in the modeling database. If you omit NAME, Adams/View
constructs a default identifier, such as MENU_4 or BUTTON_7.
• HELP = Text that appears in the status bar or tool tips describing the button.
• CMD = Command, sequence of commands, that the button executes.
Example
BUTTON2 &Export
NAME=export
HELP=Write data to file
CMD=interface dialog_box display dialog_box_name=.gui.file_export
TOGGLE
A toggle creates a menu entry that toggles between two states. It creates a check mark depending on the
state value (on or off). Make sure that if you create a toggle, you maintain its state. A TOGGLE can be
on a pull-down or sub-menu.
Syntax
TOGGLEn TITLE
NAME=name
HELP=help
STATE=state
CMD=command
Parameters
• n = Number identifying the placement of the toggle. Can be either:
• n = 2 - Toggle appears on pull-down menu
• n = 3 - Toggle appears on a sub-menu
• TITLE = Toggle name that appears in the pull-down or sub-menu.
• NAME = Text that identifies the toggle so that you can define keyboard shortcuts and
mnemonics for it. If you omit NAME, Adams/View constructs a default identifier, such as
MENU_4 or BUTTON_7.
• HELP = Text that appears in the status bar or tool tips describing the toggle.
• STATE = Current state of toggle (on or off).
• CMD = Command to execute.
SEPARATOR
A separator creates a horizontal line between menu entries on either a pull-down or sub-menu to indicate
groups of comments.
Syntax
SEPARATORn
Parameters
• n = Number identifying the placement of the separator. Can be either:
• n = 2 - Separator appears on pull-down menu
38 Adams/View
Customizing Menus Using the Menu Builder
Example
SEPARATOR2
These menu commands are helpful if you have a new version of Adams/View or created a new Modeling
database and want to read in your customized menus.
To import text:
1. In the Menu Builder, place the cursor at the location you want to bring in the text.
2. From the Menu Builder File menu, select Import.
3. Enter the name and location of the text file containing the menu text.
4. Select OK.
Note: You cannot customize all Adams/View dialog boxes and tools. For example, you cannot
customize the Plugin Manager or the Information window. The Dialog-Box Builder's
Dialog Box -> Open menu provides access to those dialog boxes, containers, and toolbars
that you can customize.
Note: You cannot customize all Adams/View dialog boxes and tools. For example, you cannot
customize the Plugin Manager or the Information window. The Dialog-Box Builder's
Dialog Box -> Open menu provides access to those dialog boxes, containers, and toolbars
that you can customize.
Interface 41
Customizing Dialog Boxes Using the Dialog-Box Builder
Tip: After displaying a dialog box from the Tools menu, you can double-click the
background of a displayed dialog box to display the Dialog-Box Builder and modify
the dialog box.
Adding Objects
You can add Interface objects to your dialog box.The instructions for adding objects to your dialog box
are the same for all types of objects.
You can also click the left mouse button, and Adams/View creates an object of default size.
Adding Images
You add an image to your dialog box just as you add a label. The image format for the label must be:
• Motif - .xbm (X BitMap) or .xpm (X PixMap)
• Windows - .bmp (must be a 16-color bitmap)
You cannot size the image in the Dialog-Box Builder. Therefore, if you want to fill the entire dialog box,
you'll need a very big image.
For sample images, see the directory /install_dir/aview/bitmaps where install_dir is the directory where
you installed your Adams products.
To add an image:
1. On the Create menu, select Label.
2. Draw the label so it fits the size of the image.
3. Double-click the label to activate it.
Interface 43
Customizing Dialog Boxes Using the Dialog-Box Builder
Tip: To see the image, you may need to select Test Box from the Options menu.
• Using the Arrow tools in the Dialog-Box Builder. The tools move objects
to the edges of the dialog box or to the edges of other objects. The tools are located along the top
of the Dialog-Box Builder.
Learn about Setting Distance Between Interface Objects.
6. Select Apply.
To increase the size of objects using the last four arrow icons on the
Dialog-Box Builder toolbar:
1. Select the object(s).
2. Click on the arrow icon indicating the direction in which you want to increase your object(s).
2. Increase or decrease the size of your object by moving the reshaping handles.
5. Select Apply.
To make two or more objects the same height or width with respect to the first object
you select:
1. Select the objects. The height and width are with respect to the first object you select.
2. Select one of the following:
• Height tool to make objects the same height.
• Width tool to make objects the same width.
2. Enter a value for Horizontal and Vertical Border Width to specify the distance from the object
to the dialog box border.
3. Enter a value for Horizontal and Vertical Separation to specify the distance between other
interface objects.
Note: Because the snap grid points are not visible, and the default grid is very fine (2 pixel
distance), snapping is not very noticeable by default.
Note: The following steps only include instructions for linking your dialog box to a help file; they
do not explain how to create HTML help files. Refer to HTML reference guides.
2. In the Tip Text text box, enter the text you want displayed in the Status toolbar (at the bottom of
the Adams/View window) when your dialog box is open.
3. In the Help File text box, enter the complete path and file name of your help file.
Note: You do not need to complete the Help Link text box. It is used for backward
compatibility only.
Include identifiers starting with the symbol $, to indicate where to substitute text. There are four kinds of
substitutions:
IFor example, to include the contents of the field my_value in a command, you
enter:
By default, the value of an option menu or radio box is the text of the displayed
or selected button. By default, the value of a toggle is on or off.
You can specify other values for Adams/View to substitute. In the toggle
button Value attributes, there are fields to set the toggle values. In the Option
Menu and Radio Box Value attributes, you can add a substitution value after
the text for each choice, separated by a vertical bar "|". The values do not affect
the displayed text; they are only used in commands.
The Object: Has the value:
Field Contents of field
Option-menu Selection of value for current selection
Radio-box Selection or vale for current selection
Toggle button On/off or specified on/off value.
Slider Integer slider value
50 Adams/View
Customizing Dialog Boxes Using the Dialog-Box Builder
$_value $_value substitutes the value of the object that contains the command. For
example, if the commands are on a button named my_toggle, $_value is the
same as $my_toggle. Another example might be if you want to create a toggle
button that returns a value of "1" or "0". You would do so with commands like
the following:
if condition=($_value)
! commands executed when user turns on toggle
else
! commands executed when user turns off
toggleend
Wherever possible, you should use $_value instead of the name of the actual
object because it is easier to understand and maintain since it does not rely on
the name of the object holding the command. If you see $_value in a
command, you know immediately that it refers to the value of the interface
object. In addition, if you change the name of the object, you do not need to
change the commands. You will find this especially helpful for toggle buttons,
radio boxes, and option menus, where you almost always want the value of the
object in the associated commands.
$_self, $_parent, These substitute the name of the object executing the commands, the object's
$_topgui immediate parent, or the parent dialog box, window, or toolbar. When
Adams/View executes the commands, it substitutes the full database name of
the appropriate object.
$_self, $_parent, and $_topgui help you make your dialog boxes easier to read
and maintain. For example, a dialog box can load one of its child fields with
this command:
Note that $_value and $_self are different, but easy to confuse. $_value inserts
the value of the object, $_self inserts the name of the object.
Interface 51
Customizing Dialog Boxes Using the Dialog-Box Builder
$_1, $_2, $_3,... These refer to parameters passed with a window or dialog-box display
command.
The window or dialog-box, and any child of the window or dialog box, can
include $_1,... in the commands. When Adams/View executes the commands,
it substitutes the current value of the parameter. This allows you to pass
information to a window or dialog box as you display it. You might, for
example, pass the name of an object to a dialog box. Commands executed by
the dialog box or objects in the dialog box can then refer to this object.
$_1, $_2, $_3,... These refer to parameters passed with a window or dialog-box display
command.
The window or dialog-box, and any child of the window or dialog box, can
include $_1,... in the commands. When Adams/View executes the commands,
it substitutes the current value of the parameter. This allows you to pass
information to a window or dialog box as you display it. You might, for
example, pass the name of an object to a dialog box. Commands executed by
the dialog box or objects in the dialog box can then refer to this object.
Example
Conditional expansion allows for the commands for custom interface objects to ignore parameters in
which the user does not enter any value. Back quotes [ parameter=value ] indicate parameters that will
be collapsed when the command is executed. This makes the resulting custom interface object easier to
use and relieves you from having to handle error checking for empty fields.
52 Adams/View
Customizing Dialog Boxes Using the Dialog-Box Builder
The Easy Beam Properties custom dialog box below shows how conditional expansion can be used.
The command for this dialog box modifies the indicated beam's properties as shown below:
force modify element_like beam &
beam_name = $f_beam_name &
youngs_modulus = $f_youngs_modulus &
shear_modulus = $f_shear_modulus &
damping_ratio = $f_damping_ratio
The problem with this configuration is that the user must enter all of the fields in the dialog box or the
entire command fails. For example, if the user left the Damping Ratio Field blank, its command would
fail with the following error:
ERROR: ---------------------------------------
ERROR: Invalid input. Enter a number.
ERROR: The command was not executed.
ERROR: &> damping_ratio =
ERROR: -------------------------------
If the command is modified to incorporate conditional expansion, the user could leave fields blank
without affecting the execution of the command.
To add the conditional expansion, you add back quotes ( ) for each parameter. The resulting command
looks like the following:
force modify element_like beam &
beam_name = $f_beam_name &
youngs_modulus = $f_youngs_modulus &
shear_modulus = $f_shear_modulus &
damping_ratio = $f_damping_ratio
Now the command can handle blank fields. For example, if the user of the dialog box leaves the Shear
Modulus field blank with the new command, the following command is executed:
force modify element_like beam &
beam_name = .model_1.ebm_beam4 &
Interface 53
Customizing Dialog Boxes Using the Dialog-Box Builder
Example
You can display windows and dialog boxes with a list of parameters. These parameters can be used by
the interface objects and commands within that interface object. The parameters are passed as quoted text
strings into the interface object.
Once the window or dialog box is displayed, it can make use of these parameters in its own commands.
These parameters are automatically assigned the special names $_1, $_2, ..., $_n, for each parameter that
is passed to it.
This functionality is especially useful for specifying default values for fields or other interface objects in
the new window or dialog box. For example, a button labeled Easy Beam Size has been added to the
54 Adams/View
Customizing Dialog Boxes Using the Dialog-Box Builder
custom Easy Beam Properties dialog box. The button contains commands that display a new dialog box
for further modification of a beam:
The name of the beam is passed to the new dialog box so that it automatically loads the relevant
parameters. The command for the Easy Beam Size button is:
interface dialog_box display &
dialog_box_name = .gui.db_beam_size &
'parameters="$f_beam_name"'
In addition to specifying the name of the dialog box to open, the command also specifies a parameter to
pass to the new dialog box.
The start command for the new Easy Beam Size dialog box uses this passed parameter to automatically
load the current values for the beam as shown below:
if condition=("$_1" != "")
interface field set field_name=$_self.f_beam_name str="$_1"
end
if condition=("$f_beam_name" != "")
interface field set &
field_name=$_self.f_length &
database_field="$f_beam_name.length"
interface field set &
field_name=$_self.f_area_of_cross_section &
data_base_field="$f_beam_name.area"
interface field set &
field_name=$_self.f_i_marker_name &
database_field="$f_beam_name.i_marker_name"
name of the beam). The second if statement checks to see if the field was set to a beam name. If so, it gets
the current values for the beam and sets the appropriate fields.
Window and dialog box parameters are useful tools for communicating information between interface
objects. To pass multiple parameters, separate them with commas, as in the following example:
interface dialog_box display dialog_box=my_dialog_box
parameters="parameter1", "parameter2", "parameter3"
When the new dialog box appears, it has access to those parameters as $_1, $_2, and $_3, respectively.
Editing Commands
Holding down the right mouse button over the Commands area of the Dialog-Box Builder displays a
shortcut menu with several options for editing the commands as shown in the table below.
Note: You can also save your dialog box by saving your modeling database as a binary file.
All of your changes are saved if you save a binary file.
Before you reload your dialog box, note that Adams/View does not allow the command file to create
interface objects with the same names as objects that already exist in the database. You must delete or
rename to read in the command file.
This is the most reliable way of ensuring your custom dialog boxes are upwardly compatible with new
versions of Adams.
Authoring Plugins
Authoring Plugins 57
Introduction
Introduction
By definition, a plugin is a computer program that can or must interact with some other program to
provide a specific functionality. Plugins typically use the UI of their parent program and rely on the native
environment of their parent to provide this functionality.
Plugins in Adams
Adams provides plugins as a very powerful way of customization. With plugins, the end user can modify
the Adams environment to suit their needs. This may involve anything from personalizing the UI (menus,
adding custom dialogs etc.) to writing custom routines, directly called by the Adams/Solver at runtime.
Information is organized into the following sections:
• Section 1 - This section talks in brief about the files that constitute a plugin, their contents and
their role
• Section 2 - This section talks about the locations in which the plugin files can reside
• Section 3 - This section talks about the directory structure in which the files should reside in one
of the locations.
58 Adams/View
Section 1: The basic plugin
Plugin xml
The plugin xml serves to publish the existence of a plugin to the product (View, Car, PPT etc). The plugin
manager makes use of the xml files that belong to the individual plugins to create a consolidated list of
plugins that is available for use with the current product.
Among other things, the xml contains information such as the plugin name, version and author as well
as the list of products with which the plugin is compatible. This information is made use of by the plugin
manager to display the information about the plugin in its UI as shown below,
It is recommended, that while creating new plugins, existing plugin xml files be used as reference.
Explanation for some of the most common tags in the xml file is given below,
• Description - Specifies a short multi-line description of the plugin.
• Version - Specifies the version number of the plugin.
Authoring Plugins 59
Section 1: The basic plugin
• Author - Contains information such as the name of the person/organization that created the
plugin.
• LicenseFeature - Contains information related to the licensing feature used by the plugin. The
plugin manager uses this information to denote the number of available licenses.
• ValidWith / NotValidWith - List of the products that the plugin is valid for use with and
otherwise. Only plugins specified in the ValidWith list are displayed in the plugin manager.
The naming convention for the plugin xml file is (plugin_plg.xml), where plugin is the placeholder for
the actual name of the plugin.
View GUI
The view GUI is a full or a partial binary file containing a View library object. The library has the same
name as that of the plugin (.plugin). The library object typically contains all the macros, UDE definitions
and dialog boxes which the plugin makes use of.
The library object also contains a load macro (.plugin.load). The load macro is typically responsible for
making changes to the parent UI (like adding plugin specific menus to the parent UI) during the plugin
load operation. It is important that the load macro uses a User-Entered Command, for instance:
myplugin load
The user-entered command is required to have the load macro called upon plugin startup. For this, it
might reference other menu or command files. After Adams/View loads the binary, the plugin library will
be searched for this macro for the load process to continue.
The View library object will also contain a corresponding unload macro (.plugin.unload). The unload
macro is complementary to the load macro and usually restores the parent environment when the plugin
is unloaded.
60 Adams/View
Section 1: The basic plugin
Also, plugin dialog boxes should have commands which call plugin specialized macros instead of
building long command structures in the dialog boxes itself. The plugin load operation automatically sets
an environment variable within the Adams/View session which helps locate the binary file from which
the plugin was loaded. The variable name is plugin_BIN_DIR where plugin is the upper-cased version
of the plugin name. This can be used in the plugin load macro, for instance, to read gui components that
are inside the plugin library.
Example:
macro create macro = .plugin.load &
user = “mdi plugin load” &
com = “file binary read &”, &
“ file = (getenv(\” PLUGIN_BIN_DIR \”) // \” plugin.bin \”) & “, &
“ entity = .gui.main.mbar.my_menu”
This plugin binary must be named plugin.bin (where plugin is the name of the plugin).
Note that no database object in the plugin library references any object outside of the library, otherwise
an unresolved dependency would be introduced between the plugin and the parent application.
Authoring Plugins 61
Section 1: The basic plugin
The bitmap below shows the controls plugin components as seen through the database navigator. Note
the library name (which is the name of the plugin) and the load/unload macros beneath the library.
Solver DLL
This binary contains the custom written functions/routines which are used by the solver during analysis.
The functions can be written in C or FORTRAN and can reside in any number of files. The solver dll is
created using the ‘adams2012 –c cr-u’ command.
The naming convention for the solver dll is plugin.{so, sl, dll}, with the extension specific to the platform
under consideration. The convention is not a requirement. It is a recommendation, just so that the solver
dll is easily distinguished from the view dll.
It is recommended that the solver dll have the two standard functions DLL_INIT and
DLL_TERMINATE, although having them is not a requisite. The INIT and TERMINATE functions have
the same role as the initialize and the terminate functions of a View dll. Typical initialization operations
for a solver dll include allocating memory for the plugin, checking out licenses and opening device
62 Adams/View
Section 1: The basic plugin
handles while termination operations include de-allocating the memory, returning licenses and closing
any open device handles.
The init function is called by the solver as soon as the statements FUNCTION = USER(…), ROUTINE
= libname::fname1 are encountered by the solver. Solver will not initialize the same DLL more than once.
Conversely, DLLs are automatically unloaded under the following conditions,
• A new database is opened
• Solver changed from C++ to FORTRAN or vice-versa.
• The STOP command is issued
• The FILE command is used to read a new model
Again, solver will not call the DLL_TERMINATE function more than once for each dll. Also note that
the terminate function will be called only if the init function was called in the first place.
Authoring Plugins 63
Section 2: The search path algorithm for plugin discovery
3. Site location
The site location is specific to verticals and is not applicable to View. This location is defined by
an environment variable which has the format MDI_<product_name>_SITE, where
product_name is the product under consideration. The environment variable is set to the desired
location/locations by the user in the form of a colon separated (semi-colon separated on windows)
list of directories. The site environment variable for individual products is listed below,
For a given product, the list of directories in the corresponding environment variable will be
checked for the existence of a plugin.
4. Installation path
The environment variable $topdir is set to the installation path of the Adams product. The
platform specific sub-directory (win32, hpux11 etc.) as applicable, will be searched for in the
plugin directory, if present in the installation path. Note that the environment variable
$MDI_CPU is set to the appropriate platform. So essentially, the location
$topdir/plugin/$MDI_CPU will be searched for the existence of the specified plugin.
5. Library path
On different platforms, the library path is specified using different environment variables. The list
of the library path environment variable on individual platforms is as specified below,
This variable contains a colon/semi-colon separated list of directories. Individual directories will
be searched for during the plugin load operation.
6. Current working directory
The current working directory is the last location which will be searched for the existence of the
plugin.
Authoring Plugins 65
Section 3: The Plugin directory structure