Chapter 5: APDL as a Macro Language

You can record a frequently used sequence of Mechanical APDL commands in a macro file (these are sometimes called command files). Creating a macro enables you to, in effect, create your own custom Mechanical APDL command. For example, calculating power loss due to eddy currents in a magnetic analysis would require a series of Mechanical APDL commands in the postprocessor. By recording this set of commands in a macro, you have a new, single command that executes all of the commands required for that calculation. In addition to executing a series of Mechanical APDL commands, a macro can call GUI functions or pass values into arguments.

You can also nest macros. That is, one macro can call a second macro, the second macro can call a third macro, and so on. You can use up to 20 nesting levels, including any file switches caused by the Mechanical APDL /INPUT command. After each nested macro executes, the Mechanical APDL program returns control to the previous macro level.

The following is a very simple example macro file. In this example, the macro creates a block with dimensions 4, 3, and, 2 and a sphere with a radius of 1. It then subtracts the sphere from one corner of the block.

/prep7
/view,,-1,-2,-3
block,,4,,3,,2
sphere,1
vsbv,1,2
finish

If this macro were called mymacro.mac, you could execute this sequence of commands with the following single Mechanical APDL command

*use,mymacro

or (because the extension is .mac)

mymacro

Although this is not a realistic macro, it does illustrate the principle.

This chapter provides information on the various ways you can create, store, and execute macros. It also discusses the basic information you need to use APDL as a scripting language in creating macros. APDL commands used to define and execute macros are listed in Chapter 2 of the Command Reference.