Microsoft Visual Studio Tools for Applications (VSTA)
Prerequisite Software
-
Microsoft Visual Studio 2019 (Community, Professional, Premium or Enterprise version) must be installed
in order to record, edit, or debug VB.NET and C# macros in SOLIDWORKS 2023
or later.
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
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.
After installing SOLIDWORKS:
- VSTA 1.0 .NET macros created in releases previous to
SOLIDWORKS 2021 are automatically 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 VSTA was not nstalled with SOLIDWORKS,
then all of the SOLIDWORKS macro dialog dropdowns contain only:
SW VBA Macros (*.swp)
Creating a .NET macro in SOLIDWORKS
- Read Installing VSTA.
- In SOLIDWORKS, select Tools > Macro > New.
- In the Save As dialog, navigate to the directory where to
save the project.
- Specify File name.
- In Save as type select SW VSTA VB Macro (*.vbproj)
or SW VSTA C# Macro (*.csproj).
- Click Save.
- A new instance of Visual Studio opens. See
Prerequisite Software.
- 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.
- The SolidWorksMacro class is assigned a GUID attribute. If
you change this attribute, the macro will not run.
- 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
- Read Installing VSTA.
- In SOLIDWORKS, select Tools > Macro > Edit.
- In the Open dialog, navigate to the project
folder.
- Select SW Macros in the project type dropdown.
- Select the *.vbproj or *.csproj project file.
- Click Open.
- 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
- Read Installing VSTA.
- In order to successfully upgrade a VSTA 1.0 .NET macro, the class
name, "SolidWorksMacro", and the method name, "Execute", must be
present.
If you renamed those entities in your VSTA 1.0 macro, the macro cannot be
upgraded to VSTA 2015.
- In SOLIDWORKS, select Tools > Macro > Edit.
- In the Open dialog, navigate to the SwMacro directory of the project
folder created in a previous release.
- Select SW Macros in the project type dropdown.
- Select the *.vbproj or *.csproj project file.
- Click Open.
- A new project is created in project_folder/SwMacro/upgradedmacro.
- A new instance of Visual Studio opens the upgraded
project. See Prerequisite Software.
- 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.
- 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 VSTA 1.0 macros are automatically converted to VSTA 2015:
- Follow the instructions in
Upgrading a VSTA 1.0 .NET macro created in SOLIDWORKS 2017 or earlier.
- Select Tools > Macro > Run.
- Select SW VSTA Macros (*.dll) in the file type dropdown.
- Navigate to project_folder\SwMacro\upgradedmacro\bin.
- Select the DLL.
- Click Open to run the macro.