You are here: Surpac Concepts > Macros > Overview
GEOVIA Surpac

Tcl Macros and Scripts

You can perform repetitive operations efficiently with Surpac macros.

Macros are recorded in a 'scripting' language known as Surpac Command Language (SCL). SCL is based on the widely available Tool Command Language (TCL).

Before SCL was implemented in Surpac, you could record macros as .cmd files. The .cmd macro interpreter subsystem is still included with Surpac, so you can still run .cmd files. You can also run compiled macros (.cmz files) using the MACRO PLAYBACK function.

You can start and end recording, and run macros, using functions or keyboard shortcuts.

Function Key Description  
MACRO RECORD START F4 Start recording a macro. A form is displayed where you are prompted to enter a name for the macro.  
MACRO RECORD END F5 End recording the macro. Exiting Surpac while recording the macro also ends recording of the macro.  
MACRO PLAYBACK F6 Runs a macro. A form is displayed prompting you to enter the name of the macro, the macro playback options and the arguments (10 or less) to pass to the macro.  

Running macros from the command line

You can also run macros from the command line of the operating system by typing the following command:

surpac2 macroname

Debugging SCL Scripts

It is possible to use the TclPro Debugger to step through and debug SCL scripts. To debug scripts, TclPro 1.4 must be installed on your system, and you also have to specify inside the defaults.ssi file where TclPro is installed. Below is a short guide to getting the TclPro Debugger working with your scripts.

  1. Install TclPro 1.4
  2. In Surpac, execute the SETTINGS command (Or use the menu Customise->Default Preferences). In the Miscellaneous tab, change the Scl prodebug file option so it points to the correct place. The Prodebug.tcl file is normally found in c:/Program Files/TclPro1.4/win32-ix86/bin/prodebug.tcl . If you installed TclPro to a different location, you will need to change this. If the location of this file is not specified correctly, then the Enable SCL Debugging option in the MACRO PLAYBACK form will be disabled.
  3. Before you play any scripts, start the TclPro Debugger.
  4. In the Debugger, Select the menu option File -> New Project...
  5. Click on the Remote Debugging Option
  6. Ensure that the Port number is the same as the scl_debug_port option in the Defaults.ssi file.
  7. Click OK, and it should start a new Project which Surpac will connect to.
  8. Start Surpac, or whichever product you use.
  9. Execute the MACRO PLAYBACK command.
  10. Select or type the .tcl file to debug as per normal
  11. In the MACRO PLAYBACK form, check the Enable SCL Debugging option.
  12. Click Apply, and Surpac should start the script, at which point the TclPro Debugger takes control, and execution of the script stops at the first line of the .tcl file.

Troubleshooting

As the creation of macros inevitably involves the use of a text editor, this can lead to errors in syntax when playing back your macros. Following are some tips you may like to follow when trying to track down problems within your macro:

  • When a macro aborts, check the message window.

    The error messages echoed to your message window will always indicate the type of problem and give you some idea where to look for the problem. You may have to scroll back through you message window to find where the macro failed. When an error is encountered with a Surpac Function the line number will be displayed. This doesn't mean that the problem is exactly at this line, but may be just after the line number. Remember that when Surpac reports an error for a FORM that you use a continuation character (\) within macros so that you don't end up with incredibly long lines for each form. However when Surpac reports an error for a form it will always indicate this as being the first line, it may in fact be further down than this.

  • Check Variable Names

    Variable names are case sensitive, so that a variable called level is different to a variable called Level. Always check that the spelling for variable names is consistent.

  • Check that brackets and apostrophes always close

    An error indicating a parsing problem, or a problem evaluating a function more often than not indicates that brackets and quotations aren't closed. Every "(" should have a corresponding" )".

  • Check that there are no characters after a continuation character

    Any characters (eg a TAB or a space) which fall directly after a continuation character within a form will cause the macro to fail with a parsing error.