Debugging Your Macro
If the macro does not run, you must edit the macro with the editor. The procedure for editing a macro is the same as for creating a macro: use EDIT_FILE to enter the file, and then make alterations.
When the file is displayed in the editor, you will see the first page of the file. Use the arrow keys to scroll to the macro you want to alter. Examine the macro line by line until you find the error. Most errors are simple, such as missing parentheses and missing underscores.
If you cannot find the error quickly, debug your macro using the BREAKPOINT function. Insert a BREAKPOINT in desired position in macro code. This can be done either by editing the file on disk or by using EDIT_MACRO function. When the code reaches a BREAKPOINT, the system goes into debug mode.
The breakpoint function is enabled by default. If you find that it is not working, check that ENABLE_BREAKPOINT is set to ON.
To enable the BREAKPOINT function in Creo Elements/Direct Drafting:
Click Miscellaneous and then, in the System group, click the Breakpoints check box.
When you use a breakpoint and they are enabled, the system will display a parameters table.
If already in debug mode and you have moved forward at least one token using debugger command, BREAKPOINT keyword will set a breakpoint in current position.
If you insert a BREAKPOINT between PARAMETER and LOCAL in a macro, the debugger will break before the first command in macro.
Note that the breakpoint will be set for the current OSD session only, it will not be added to correspondent file on disk.
Once in debug mode, use the following commands to step through your macro and isolate the area where it is not working:
STEP_NEXT: Use this action to step through macro code one token at the time.
STEP_OUT: Step out of current macro function.
STEP_OVER: Step over the next token even if it is a macro function.
STEP n: Step over several tokens in one step.
SKIP n: Skip current token several times.
CONTINUE: Continue with macro execution until the next breakpoint.
GO: Execute the rest of the code disregarding all breakpoints.
REMOVE_BREAKPOINT: Remove current breakpoint.
ENABLE_BREAKPOINTS: Enable all breakpoints.
LIST_BREAKPOINTS: List all breakpoints in an editor.
When you debug with BREAKPOINT, be aware of the following:
Use the DISPLAY command to see variable values as you step through your macro.
Any Creo Elements/Direct Drafting function can be executed while in break state.
Creo Elements/Direct Drafting commands will interrupt the macro.
When any macro in the call stack is modified, due to INPUT, EDIT_MACRO, DELETE_MACRO, or DEFINE commands, the debugger will also be interrupted.
The debugger does not include a user interface. See the command prompt for additional information, such as current command, last token, next token, and next command.
The debugger does not include a viewer for your code. To see your code as you debug, use an external viewer.
When you have found the error and corrected it, press [Ctrl] D to return to the ME-CAD screen. The new version of the file overwrites the old version on the disk.
The compiled version of the file in RAM remains unchanged. The only way you can alter the compiled version is to load the new version of the file into RAM using the INPUT command. A common error is to edit the file and then run the macro without using the INPUT command. This runs the old version of the macro.
Input the file again by typing:
INPUT 'cad_mac.m'
* 
If you want to repeat commands you have typed previously, press the [PgUp] key. If you want to enter a command that is similar to a previous command, press [PgUp] key, and then edit the command.
The contents of cad_mac.m are reloaded from the disk and overwrite the old copy in RAM. You can now re-execute the macro. A macro can be executed as often as you like after the file is loaded.
To summarize, when you are writing and debugging a macro called Quit in a file called cad_mac.m , use three steps:
EDIT_FILE 'cad_mac.m '
INPUT 'cad_mac.m '
Quit
There is a trace facility that is useful for debugging macros. This is described in Using the Trace Facility.
Was this helpful?