Fundamentals: Running A Macro
Instructions on how to select and launch a macro file are covered in your SmartCAM application's help file and in the Automation/Customization - Record and Playback Overview topics. A very brief explanation of the entire process is described below:
- Create your macro as an ASCII text file, one expression per line.
- Save the macro.
- Start your SmartCAM application.
- Select Macro - Execute.
- Use File Select or type in the path and name of your macro.
- Use Accept to run it.
How It Works
SmartCAM's macro system is what is technically termed a two-pass compiler. When you run a macro, SmartCAM first reads through the macro converting the macro commands into a set of machine instructions. During this compilation pass, the syntax of your macro is evaluated. If there are errors, they are written to the SmartCAM Diagnostics window. If there were no errors, the list of machine instructions are executed by a "virtual machine."
SmartCAM does not have an entry procedure, instead it starts reading the macro from top to bottom and starts running commands as soon as it reads one that can be run. If the very first line at the top of the ASCII file is a valid macro command, that is where SmartCAM will begin to run.
It will continue to run each line of macro commands, in succession, until:
- The end of the macro file is reached.
- The macro is stopped with a
HALT
macro command. - A
MAC_EXE[]
macro command is read. This macro command stands for Macro Execute and it allows you to run other macros from inside the currently running macro. When this macro command is reached, it will read and run the referenced macro. When the referenced macro is finished, it will return to the calling macro and continue to run from the very next line afterMAC_EXE[FN=""]
. - A branching statement is executed, such as
GOTO
,IF
, orWHILE
. - A semantic error is encountered that the macro system cannot resolve. At which time, an error is reported and the macro stops running.
Comments
When parsing a macro file, SmartCAM will ignore anything that follows the comment characters. Comment characters are two forward-slashes "//". Anything following the comment characters, until the end of the current line is reached, is ignored. Example:
// This entire line is ignored
#A=10 // #A is set to 10, but everything after that is ignored
// #A=11 - #A is NOT set to 11, since it comes after the comment characters
When writing a macro, use a lot of comments and thoroughly document what your macro is meant to do and what each line or block of lines is for. Using comments to document your macro will make it easier to extend the macro or debug the macro. Also the person that wrote the macro may no longer be associated with your organization when it is time to make changes. So, accurate and complete documentation will aid the new programmer understand what the macro code is attempting to accomplish.
Whitespace
Whitespace characters are characters that don't display on your monitor, such as blank lines, space characters, and tabs. They effect the formatting of text but have no specific character themselves.
SmartCAM skips over blank lines in your macro file. Using blank lines to group together related functionality, along with comments, is a good idea.
SmartCAM also skips over other whitespace characters, such as spaces and tabs. As long as the spaces and tabs do not cause macro key words to be broken. Examples:
#S = #S + 1 // this is valid
#S=#S+1 // this is also valid and is the same as above
# S = #S + 1 // this is not valid, because the variable designator is separated from the variable name
The same whitespace requirements exist for macro commands as well.
ON_LAYER[LY=1,
WP = "XY_PLANE", LV=-1,
PT=1.0]
The above is the same as:
ON_LAYER[LY=1, WP="XY_PLANE", LV=-1, PT=1.0]
While you can split up macro commands into multiple lines, this is not recommended. It makes debugging and understanding the macro logic more difficult.
Related Topics