Macros

The quickest and easiest way to start programming with the DraftSight API is to record a macro, which contains the DraftSight API calls that correspond to the actions performed interactively in DraftSight. This Help topic identifies the supported macro-recording programming languages and DraftSight interfaces and describes how to interactively and programmatically record macros.

NOTES:

Support languages

You can save macros as Microsoft Visual Studio 2008 projects, VBA script files, and JavaScript HTML files. Thus, you should be familiar with at least one of the following programming or scripting languages before using the macro recording feature of DraftSight:

Back to top

Supported interfaces

This release supports recording macros for these interfaces:

Back to top

Interactively record macros

Typically to interactively record a DraftSight macro:

  1. Plan the interactive DraftSight actions before recording the macro.
  2. Set the location where to save the macro's Microsoft Visual Studio 2008 project, JavaScript HTML file, or VBA .swb file.
  3. Set the level of detail to appear in the macro's Microsoft Visual Studio 2008 project, JavaScript HTML file, or VBA .swb file.
  4. Record the interactive DraftSight actions.

    NOTE:
    If you are unfamiliar with recording DraftSight macros, perform the interactive DraftSight actions a couple of times before starting to record the macro to eliminate possible extraneous actions such as zooming in or out of the drawing, panning, etc.
     
  5. Stop and save the macro in the language you selected.

    A Microsoft Visual Studio 2008 project, JavaScript HTML file, or VBA .swb file is created upon saving the macro at the location specified in step 2.
     
  6. Open the macro's Microsoft Visual Studio 2008 project, JavaScript HTML file in Notepad or any HTML editor, or VBA .swb file in the SOLIDWORKS VBA IDE or Microsoft Office VBA Editor.
  7. Edit, build, run, debug, rebuild, and rerun, as needed, the macro. Repeat this step until the macro is executing as intended.
  8. Save the macro's Microsoft Visual Studio 2008 project, JavaScript HTML file, or VBA .swb file.

Back to top

Interactively set macro location and level of detail

To set the location where to save DraftSight API macros and the level of detail to record:

  1. Click Tools > Options to open the Options - System Options dialog.

  2. Click the System Options button.

  3. Expand Macro Recording.

  4. Expand Location.

  5. Type the path of the location where to save macros.
    - or -
    Click Browse, navigate to the folder where to save macros, and click Select Folder.

    The location where to save macros is stored in the sysvar APIPATH.

  6. Expand Level of detail.

  7. Select the level of detail to appear in the macro:

    The level of detail is stored in the sysvar APILEVEL.

  8. Click OK to close the Options - System Options dialog.

Back to top

Interactively record and save a macro

To record and save a macro:

  1. Click Tools > Macro > Record or type _RECORDMACRO in the command window.

  2. Perform the interactive actions that you want to record.

  3. When you are done recording, click Tools > Macro > Stop or type _STOPMACRO in the command window to stop and save the macro.

  4. Type a name for the macro in File Name and select the language to which to save the generated macro code in Save as type.

  5. Click Save to save the macro in the location specified in step 5 in the previous procedure.

Interactively edit, build, run, debug, rebuild, rerun, and save a macro

To edit, build, run, debug, rebuild, rerun, and save a macro:

  1. Open the macro project in Microsoft Visual Studio 2008, JavaScript HTML file in Notepad or any HTML editor, or the VBA .swb file in the SOLIDWORKS VBA IDE or any Microsoft Office VBA Editor, in the location specified in step 5 in the Set macro location and level of detail procedure.

  2. Edit the macro code to delete any extraneous lines of code, add lines of code for actions not performed interactively while recording the macro, reformat the code, etc.

  3. Build, if needed, and run the project or file to test it.

  4. Debug, rebuild, if needed, and rerun the project or file again. Repeat this step until the macro is executing as intended.

  5. Save the project.

Back to top

Programmatically record macros

Programmatically start and stop macros

The DraftSight API includes two methods to programmatically start and stop macro recording:

These methods are useful if you want your add-in application to record and play back DraftSight macros. For example, if your add-in application allows end users to change dimension styles, then end users might want to record and play back the operations in a macro. This would allow end users to easily change dimension styles in a large number of files by playing back the macro.

Programmatically set macro location and level of detail

The DraftSight API includes properties for programmatically getting and setting:

 

Back to top