Hide Table of Contents

Microsoft Visual Studio Tools for Applications (VSTA)

Prerequisite Software

  • Microsoft Visual Studio 2015 (Community, Professional, Premium or Enterprise version) must be installed in order to record, edit, or debug VB.NET and C# macros using VSTA (3.0) 2015 in SOLIDWORKS.

    Notes:

    • If you install a version of Microsoft Visual Studio that is later than 2015, you must ensure that a runtime version of Microsoft Visual Studio 2015 is also installed.
    • If you do not install Microsoft Visual Studio before you install SOLIDWORKS, you will not be able to record, edit, or debug VSTA 3.0 macros. You will only be able to run VSTA 3.0 DLLs.
    • If you install Microsoft Visual Studio after you install SOLIDWORKS 2018, you must also install the VSTA runtime to record, edit, or debug VSTA 3.0 macros.

Installing VSTA

SOLIDWORKS 2017 and earlier used VSTA 1.0 to create, edit, and run .NET macros. As of SOLIDWORKS 2018 both VSTA 1.0 and VSTA (3.0) 2015 were supported. As of SOLIDWORKS 2021, VSTA (3.0) 2015 is activated by default on all Windows versions. VSTA 1.0 .NET macros created in previous releases are converted when they are opened in SOLIDWORKS 2021.

Windows 8 or later machines:

  1. During SOLIDWORKS installation, click Change above the Products window on the Summary screen.
  2. Expand SOLIDWORKS in the Product Selection window.
  3. Select Visual Studio Tools for Applications (VSTA).
  4. On the Summary screen, click Install Now.

After installing SOLIDWORKS:

  • When trying to open VSTA 1.0 .NET macros created in previous releases, they must be converted to VSTA 2015. After conversion, an instance of Visual Studio opens the converted .NET macro for editing. See Prerequisite Software.
     
  • Tools > Macro > Edit > Open > File name dropdown contains:
     
    • SW VBA Macros (*.swp)
    • SW VSTA VB Macro (*.vbproj)
    • SW VSTA C# Macro (*.csproj)
    • SW Macros (*.swp, *.swb, *.csproj, *.vbproj)
       
  • Tools > Macro > New > Save As > Save as type dropdown contains:
     
    • SW VBA Macros (*.swp)
    • SW VSTA VB Macro (*.vbproj)
    • SW VSTA C# Macro (*.csproj)
       
  • If you did not select to install VSTA when you installed SOLIDWORKS, then all of the SOLIDWORKS macro dialog dropdowns contain only:

        SW VBA Macros (*.swp)

 

Creating a .NET macro in SOLIDWORKS using VSTA 3.0

  1. Read Installing VSTA.
  2. In SOLIDWORKS, select Tools > Macro > New.
  3. In the Save As dialog, navigate to the directory where to save the project.
  4. Specify File name.
  5. In Save as type select SW VSTA VB Macro (*.vbproj) or SW VSTA C# Macro (*.csproj).
  6. Click Save.
  7. A new instance of Visual Studio opens. See Prerequisite Software.
  8. Solution Explorer shows:
    • The solution, VstaProjects.
    • The project name.
    • My Project
    • References (sldworks and swconst interop assemblies added from install_dir\api\redist\)
    • SolidWorksMacro.vb or SolidWorksMacro.cs.
  9. The SolidWorksMacro class is assigned a GUID attribute. If you change this attribute, the macro will not run.
  10. When you compile the macro, the project's configuration (Debug or Release) and output directory are not read. Only a release DLL is saved in project_folder/bin.

Editing a .NET macro created in SOLIDWORKS using VSTA 3.0

  1. Read Installing VSTA.
  2. In SOLIDWORKS, select Tools > Macro > Edit.
  3. In the Open dialog, navigate to the project folder.
  4. Select SW Macros in the project type dropdown.
  5. Select the *.vbproj or *.csproj project file.
  6. Click Open.
  7. A new instance of Visual Studio opens the project you selected. See Prerequisite Software.

Upgrading a VSTA 1.0 .NET macro created in SOLIDWORKS 2017 or earlier

  1. Read Installing VSTA.
  2. In order to successfully upgrade a VSTA 1.0 .NET macro, the class name, "SolidWorksMacro", and the method name, "Execute", must be preserved. If you renamed those entities in your VSTA 1.0 macro, the macro cannot be upgraded to VSTA 2015.
  3. In SOLIDWORKS, select Tools > Macro > Edit.
  4. In the Open dialog, navigate to the SwMacro directory of the project folder created in a previous release.
  5. Select SW Macros in the project type dropdown.
  6. Select the *.vbproj or *.csproj project file.
  7. Click Open.
  8. A new project is created in project_folder/SwMacro/upgradedmacro.
  9. A new instance of Visual Studio opens the upgraded project. See Prerequisite Software.
  10. When you compile the macro, the project's configuration (Debug or Release) and output directory are not read. Only a release DLL is saved in project_folder/SwMacro/upgradedmacro/bin.
  11. The original macro is not modified or moved.

Running a VSTA 1.0 .NET DLL created in SOLIDWORKS 2017 or earlier

Read Installing VSTA. VSTA 2015 is active by default, and you must now upgrade VSTA 1.0 macros to VSTA 2015:

  1. Follow the instructions in Upgrading a VSTA 1.0 .NET macro created in SOLIDWORKS 2017 or earlier.
  2. Select Tools > Macro > Run.
  3. Select SW VSTA Macros (*.dll) in the file type dropdown.
  4. Navigate to project_folder\SwMacro\upgradedmacro\bin.
  5. Select the DLL.
  6. Click Open to run the macro.


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:   Microsoft Visual Studio Tools for Applications (VSTA)
*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) 2021 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.