Professional Documents
Culture Documents
Macro Basics
Training Manual
...Macro Basics
Training Manual
Macro Basics
A. Creating a Macro
To create a macro, simply start a text editor, insert the
desired sequence of commands, and save them to a file
called name.mac.
name can be up to 32 characters, starting with a letter.
Spaces are not allowed in the name.
Also avoid special characters.
Training Manual
Macro Basics
...Creating a Macro
Example:
A macro totvolume.mac to calculate the total volume of all
elements:
esel,all
etable,volume,volu
ssum
*get,totvol,ssum,,item,volume
*stat,totvol
Training Manual
Macro Basics
...Creating a Macro
Search Path:
ANSYS will execute the first name.mac file it finds in the
following search sequence:
1. /ansys60/docu
Training Manual
Macro Basics
Training Manual
Macro Basics
Training Manual
esel,s,type,,arg1
! Select elements of specified type
etable,volume,volu
! Store volume in element table
ssum
! Sum element table items
*get,totvol,ssum,,item,volume
! totvol = sum of volume
*vwrite,arg1,totvol
! Write out arg1 and totvol
(Total volume for type , F4.0, elements = , F8.2)
Macro Basics
Training Manual
Macro Basics
C. Branching
Training Manual
Additional comparison operation are available for the *IF and *ELSEIF
commands with AND, OR, or XOR options.
*IF,A,EQ,B,AND,C,GT,D,THEN
Branching begins with *IF and ends with *ENDIF. *ELSEIF and *ELSE
are also allowed in between:
*if, x, eq, y, then
*else
*endif
Macro Basics
...Branching
Training Manual
!x=y
x, NE, y
!xy
x, LT, y
!x<y
x, GT, y
to execute the
subsequent block of
commands
!x>y
*EXIT
to exit a do-loop
x, LE, y
!xy
x, GE, y
!xy
x, ABLT, y
x, ABGT, y
Macro Basics
...Branching
Training Manual
Macro Basics
D. Looping
Training Manual
Macro Basics
...Looping
Training Manual
Macro Basics
E. General Guidelines
Training Manual
As you create the macro, remember that you can cut and
paste the commands into the ANSYS Input window to test
and make sure that the command sequence is correct.
Macro Basics
F. Workshop
This workshop consists of the following problem:
W9. Verifying Pressures
Training Manual