ANSYS Macro Programming With The
ANSYS Macro Programming With The
Command
This article illustrates APDL programming with subroutines through the *USE command and
a macro library file. One large macro file can be used to execute many related subroutines and
optionally to define and support many toolbar buttons that execute complex procedures.
Construction of a Macro File with Subroutines
There is a way to write APDL programs that contain their subroutines in a single file, taking
advantage of the *USE command. A package of macros for one purpose does not have to
consist of a series of .mac files stored in one or multiple locationsall can be packaged in a
single .mac file. This can aid simplicity in version control and distribution. The technique keeps
all related macros inside one source file. An example illustrates.
This example starts in a main routine by declaring itself as a macro library with the *ULIB
command. The *ULIB command calls its own file using its own file name. It calls subroutine
macros inside itself with the *USE command. These subsidiary macros are positioned after the
main macro ends with the /EOF command. The principal trick in getting this technique to
work is to immediately follow each /EOF command that ends a block with the Label for the
next *USE macro block. Comments on each section follow the Label for the block that is a
subsidiary macro for the *USE command.
! End of "part1"
/EOF
PART2
! Part 2 of the macro library,--the second label.
!
! Description of part2 of the macro library.
!
*msg,UI
Part 2 of the macro
/wait,1
! End of part 2
/EOF
Below is the note that appears at the end of the run of the above macro:
Conclusion
A macro library file identified by the *ULIB command can access blocks inside itself with
*USE commands, passing argument lists are required. This gives the user an APDL
programming approach that permits a main routine, followed by many subroutines, all
contained in one source file. The approach lets users employ one source file, rather than a large
set of macro files that must be kept together, when complex APDL programming is wanted.
A supplementary use of a macro library is to support a set of Toolbar buttons that execute blocks
inside the macro library by executing *USE commands when clicked. This permits Toolbar
buttons to execute complex APDL command sequences contained inside the blocks.
These approaches aid the use of complex APDL programs and Toolbar button actions, giving
more power to ANSYS users.
Critical to operation of the APDL macro library is to follow an /EOF command immediately
with the Label for the next block of commands.