A Beginners Guide to Creating SolidWorks Add-ins

The journey of creating a commercial software tool has been a learning experience for me, and also a good opportunity to share some of the challenges I encountered in hopes of helping other would-be SolidWorks API developers who are just getting started; whether you are creating tools for yourself, for a team of SolidWorks users, or you are an entrepreneur with an idea. Although I’ve been writing SolidWorks applications for over a decade, I remember how daunting it felt to get started, and the unlimited possibilities unlocked by just a little bit of knowledge.

In this, the inaugural CAD Innovations blog post, I decided I would start at the beginning, and walk through the steps to create and release a SolidWorks add-in. There are lots of great resources on the web covering many aspects of this process, but I would like to pull these together and add some tips based on my experience in hopes of creating a comprehensive ‘start to finish’ guide. If you run into problems, or have a topic you would like me to delve into, leave a comment below and I will add more information or cover in a future blog post.

If you have ever created, edited or even simply clicked ‘run’ on a SolidWorks macro (there are thousands available for free, for example Lenny’s popular SolidWorks macros), you are likely familiar with their simplicity – write a few lines of code or download someone else’s, run the macro, and watch the magic happen. Creating and deploying a SolidWorks add-in requires a few more steps, but provides a solution that can seamlessly integrate with SolidWorks, including the ability to add custom menus, icons, toolbars, property manager pages, task pane tabs, take action on events, and more.

Let’s compare some of the similarities and differences between SolidWorks macros and add-ins:

Programming Language(s)VBA*VB/C# .NET, C++/CLI
Easily incorporate into SolidWorks UINoYes
Supports asynchronous/multi-threaded processesNoYes
Code hidden from usersNoYes
Supported by version control systems**NoYes
* Although it is possible to use .NET with VSTA macros, this is not recommended
** To be covered in a future blog post

For those reading this with experience writing VBA macros (either for SolidWorks, or even Excel macros), VB .NET is likely the easiest language to use when getting your feet wet with SolidWorks add-ins. The syntax is similar to VBA, but with many more features and without some of the confusing and seemingly extraneous idiosyncrasies of VBA. On the other hand, if you already know (or are willing to learn) C# or C++, there are some advantages: due to the ubiquity of, say, C# there are significantly more resources on the web to help if you get stuck (especially with more advanced issues). Visual Studio also supports predictive auto-complete for C# (super helpful) while you won’t see this support for VB .NET.

To get started, you will need to download the SolidWorks SDK from the SolidWorks Customer Portal, and Microsoft Visual Studio. The permitted use for the community edition has some limitations, so read the license terms carefully (basically, companies exceeding 250 employees or 1M revenue may not use the free version), but in my experience the Professional license is reasonably priced. Once you have installed both, you’re all set… maybe. Rarely do the SDK templates appear in the Visual Studio new project template list on their own, but thankfully there is an easy fix.

Now, you’re ready to create your first SolidWorks add-in. Open Visual Studio, select ‘Create a new project’

Scroll down to the SolidWorks add-in templates (again, VB .NET is recommended for those with VBA experience), and hit ‘next’. Give the project a name and hit ‘Create’. The sample add-in provided by the SolidWorks SDK includes all of the code necessary to register the add-in, connect to SolidWorks, add sample menu items and set up a property manager page. The sample also includes an event handler class with access to commonly used SolidWorks events (such as opening, closing and saving documents).

If you have ever poked around the windows registry, you may have noticed that every application has an alphanumeric identifier. This randomly generated 36 character string is called a Globally Unique Identifier (GUID), ensures that no two applications are assigned the same value (hence the ‘globally unique’ moniker). You’ll need to generate your own GUID for your application, which is easy thanks to the web. When you have created a GUID and copied to your clipboard, replace the GUID at the top of the SwAddin.vb file (or SwAddin.cs if you created a C# add-in) in your Visual Studio project, like this C# example from the Versa Note add-in:

[Guid("BB75C0FD-3720-45E5-8B80-2ACB34900F7E"), ComVisible(true)]
    Description = "Versa Note AddIn",
    Title = "Versa Note",
    LoadAtStartup = true

Depending on the version of Windows you are running and other software on your system, the project may not be configured for the version of .NET installed. To check this, right click on the project name in the Visual Studio solution explorer and select ‘Properties’. Under the ‘Application’ tab, ensure a ‘Target Framework’ is selected from the dropdown.

The latest .NET framework is 4.8, and generally speaking this is the safest choice. If you want to ensure maximum compatibility across systems in your organization without the hassle of upgrading the .NET framework on every system, you may opt to select the lowest available framework (or even install a lower framework on your development system). After selecting the target framework, you will be prompted to confirm the change; hit ‘Yes’ to proceed.

Now you’re ready to build and test your very first SolidWorks add-in. Assuming the computer you installed Visual Studio on also has SolidWorks, you simply need to select the ‘Release’ solution configuration (which should be in the ‘Standard’ toolbar in Visual Studio) and under the Build menu, select ‘Build Solution’. Assuming the build completes with no errors, open SolidWorks and open the ‘Tools’ menu. You should see an add-in called ‘VB Addin’ or ‘C# Addin’ (the displayed name of the add-in can be modified in the SwAddin.vb (or SwAddin.cs) file):

#region UI Methods
public void AddCommandMgr()
    ICommandGroup cmdGroup;
    if (iBmp == null)
        iBmp = new BitmapHandler();
    Assembly thisAssembly;
    int[] cmdIndex = new int[4]; //, cmdIndex1;
    string Title = "C# Addin", ToolTip = "C# Addin";

That’s it for now. I’d love to hear your feedback, and suggestions for future topics. Given that there are endless applications for SolidWorks add-ins, it is hard to answer every possible question, but I will continue to pick interesting tidbits from the Versa Note development journey, with a focus on the SolidWorks specific aspects (since that’s why you’re here, right?)