Macro Language Reference > Macros > System > automac
  
automac
Description
Allows macros to be run automatically without user intervention, by being triggered when the assigned expression changes. Up to 5 expressions/macro pairs can be active at once. You can choose whether the expressions are checked when PTC ALD is idle and/or during the execution of PTC ALD scripts. Automatic macros can be suspended individually or all together.
 
Example 213. Suspend automatic macro 1
automac 1,0,0
 
Example 214. Execute a named script every 10 minutes
automac "(v21022/(10*60))","trun ""time_out""
 
Example 215. Execute a numbered script when the top document window changes
automac "(v01504)","trun 390"
 
Example 216. Execute automatic macro 1 on evaluation of an expression
automac 1,-9999
 
Example 217. Identify automatic macros via the idx macro number
When APP executes the macro, a single %d sequence can be replaced with the idx number of the macro. This can be used to pass the idx number to a script. The script can then use this number to suspend the automatic macro or otherwise. The number is accessed from within the script using %b, a standard feature of trun, for example: :
automac "(v21022/600)","trun ""timer"",""%d""
 
Example 218. Resume automatic macro 1
automac 1,0,1
 
Example 219. Automatic macros with events in scripts
This advanced example is executed by a template's autoexec script and carries out the following conditional actions:
If v21812 (the script line number) changes, increase the variable _AX_P_ and send the comment event 600 with the variable value as its parameter.
If v1818 (the script name) changes, increases the variables _AX_S_ and send the comment event 601 with the variable value as its parameter.
automac 1,"v21812",0,"(^_AX_P_++):(event 601,^_AX_P_^)",2;
2,"v1818",0,"(^_AX_S_++):(event 600,^_AX_S_^)",2
Adventtest.exe (the sample wrapper program delivered with APP OCX builds) displays the event number and the event parameter it receives from APP at the bottom left of the window; for example, event 600,1 would show 600 in the first field and 1 in the second.
 
Pre APP version 2.3, the number of received events is not displayed so the only way to see, on screen, consecutive events with identical numbers is to change their parameters. Hence the slightly unusual sample seen here.
Syntax
automac ( ( -:L ) | ( +:L ) )? idx:n? expression:s last:n macro:s mode:n
automac
[no parameter]
Invoke the Automatic Macros dialog box.
-
Deactivate automacro checking.
+
Activate automacro checking.
idx
The automatic macro: a number from 1 to 5
expression
The PTC ALD expression whose evaluation will trigger the macro
last
The last result of the PTC ALD expression (this is not normally supplied, but it appears in the dialog box for information. By changing it to an abnormal value, you can force the corresponding macro to be executed the next time the expression is evaluated).
macro
The macro to be executed upon evaluation of the expression. Any double quotes in the macro must be doubled up, since the whole macro must be in double quotes. For example:
"trun ""my_script""".
 
This does not apply when defining automatic macros via the dialog box.
mode
At what point(s) to check for changes to the expression:
0
Off (suspended)
1
During PTC ALD time (default)
2
During script processing
3
During idle time and script processing
Additional Information
 
The 5 automatic macros are global to PTC ALD , not document specific. If you are using them to start scripts in a document that document must be active for the script to run.
 
It is not guaranteed that an automatic macro will be run when only the expression has changed: this will only happen when the expression is evaluated and its result is different from the last time it was evaluated.