Hide Table of Contents

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:

  • Macro recording is available in DraftSight Premium only.

  • You must use Microsoft Visual Studio 2008 to edit, debug, and build C++ Native, C#, VB, and C++ COM macro projects.

Supported 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:

  • C++ Native (*.vcproj): Creates a Microsoft Visual Studio 2008 project and an add-in (.dll) in which you implement a command that executes the generated macro code. If you edit and rebuild the add-in after loading it, then you must close and restart DraftSight to reload the add-in.

  • C# (*.csproj): Creates a Microsoft Visual Studio 2008 project and an external application (.exe) that executes the generated macro code that you can edit, rebuild, and rerun the project without closing DraftSight.

  • JavaScript (*.html): Creates an HTML file from which you execute the generated JavaScript macro code. Open the HTML file in a web browser and click the button to execute the macro.

  • VB (*.vbproj): Creates a Microsoft Visual Studio 2008 project and an external application (.exe) that you can edit, rebuild, and rerun the project without closing DraftSight. This type of Microsoft Visual Studio project is also commonly referred to as a VB.NET project.

  • C++ COM (*.vcproj): Creates a Microsoft Visual Studio 2008 project and add-in (.dll) in which you implement a command that executes the generated macro code. If you edit and rebuild the add-in after loading it, then you must close and restart DraftSight to reload the add-in.

  • VBA (*.swb): Creates a script file that you can:

    • Open, edit, debug, and run in the SOLIDWORKS VBA Integrated Development Environment (IDE).

    • Import into any Microsoft Office product that supports macros.

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:

    • Low: Minimal code required to emulate interactive actions and execute.

    • High: Verbose code, including intermediate steps, required to emulate interactive actions and execute.

      NOTE: Data recorded in macros for methods that expect users to input data at the prompt in the command window, e.g., ISketchManager::InsertCircle, are ignored when executing the macro. Instruct your users to examine the command window to determine if they must input data at the prompt in the command window when recording macros with the high-level of detail option selected. You might also want to delete the lines of code in the macro that prompt for data.

    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



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Macros
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:




x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2023 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.