< Back

Calling a Macro from Another Macro


Problem:

I have a few macros that I use often and want to call them from within another macro.

Solution:

Tecplot 360 allows for macros and macro functions to be called from other macro files via the $!INCLUDEMACRO command.

For example, if you have a macro function to post an equation in a file called add_text.mcr:

#!MC 1410
$!MACROFUNCTION NAME = "Equation"
$!AttachText
  AnchorPos
    {
    X = 10
    Y = 5
    }
  TextType = LaTeX
  Text = '$x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$'
$!ENDMACROFUNCTION

This can be callable from another macro file like below:

#!MC 1410
$!INCLUDEMACRO "|MACROFILEPATH|/add_text.mcr"
$!PROMPTFORYESNO |answer|
  INSTRUCTIONS = "Do you want to place the equation?"
$!IF "|answer|" == "YES"
  $!RUNMACROFUNCTION "Equation"
$!ENDIF

Because the add_text.mcr file was included, the macro knows about the macro function, “Equation”. This can be especially helpful if you are running the same macro function multiple times.

Macro functions can also be passed arguments increasing their effectiveness. For more information, see $!RUNMACROFUNCTION in the Tecplot 360 Scripting Guide.