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 technically referred to as a two-pass compiler. When you run a macro, SmartCAM first reads through the macro, converting the macro commands into a set of instructions. During this compilation pass, the syntax of your macro is evaluated. If errors occur, they are displayed in the SmartCAM Diagnostics window. If there were no errors, the list of instructions would be executed by a "virtual machine."
SmartCAM does not have an entry procedure; instead, it reads the macro from top to bottom and executes instructions as soon as it encounters one. 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
HALTmacro command. - A
MAC_EXE[]macro command is read. This macro command, Macro Execute, 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 many 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 who 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 in 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 affect the formatting of text but do not have a specific display character of their own.
SmartCAM skips over blank lines in your macro file. Using blank lines to group 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 keywords 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