Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Want to improve this question? Update the question so it focuses on one problem only by editing this post .

Closed 5 years ago .

Can you put this in a Q&A format? It's more "in keeping" with Stack Overflow's usual structure. EJoshuaS - Stand with Ukraine Aug 13, 2018 at 14:05 I'm not sure how to change the format. Sorry, i've been on Stack Overflow's for quite a while but never really participated :p Michaël Corriveau-Côté Aug 13, 2018 at 14:09 The main thing is to add this part as an answer and then to add a question that it's intended to answer. EJoshuaS - Stand with Ukraine Aug 13, 2018 at 14:10 Yep, that's a good structure. I upvoted as this seems like a valuable thing to know how to do. EJoshuaS - Stand with Ukraine Aug 13, 2018 at 14:29

I'd like to share my experience on building a C# addin for Solidworks 2016 using Visual Studio Professional 2017 and Windows 10. I wish I had such a post to save me time so I think future users could find help into this one.

1. Downloading the C# template for visual Studio and installing it

I basically followed the steps provided by Solidworks (requires a Solidworks Customer Portal account) that you can find here :

Problem Encoutered : The exe would be extracted into a MSI and then the MSI would run. Once the installation done, I couldn't find the template project in Visual Studio, neither in its folder ( C:\Users[UserName]\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C# )

Solution : I found this post that suggest unziping the MSI using 7zip. Sure enough, that solution worked for me and I was able to copy the zipfile ( swcsharpaddin.zip ) in its respectives folder.

2. Creating a C# Soliworks Project with Visual Studio.

You can found what information Solidworks provides here

Once the .zip file is in the templates folder of Visual Studio, you should have this new option when creating a C# project.

First, if you get this error , you'll need to change once the project is created is the .Net Framework version of your project. You can do so by going in the Project Properties and changing the framework to a version equals or higher than the one of the DLLs. (4.0.0.0 here)

Second, if you get this error , you'll need to include the C# reference. Just right-click reference, Add Reference, Assemblies, check Microsot.CSharp.

Third, I personally had to change the project Platform Target to x64 in order for my Addin to RegisterCOM.

Once these steps are done, you may build your project. Since this template is by default "COM Visible" and "Register for COM interop", the function named RegisterFunction in swAddin.cs should be called on Buid (and UnregisterFunction on Clean). Note that if you place a breakpoint in this function, it won't be hit.

You should then see your addin info in Computer\HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\AddIns[GUID] with the informations provided in the top of your SwAddin.cs.

    /// <summary>
/// Summary description for SwCSharpAddin1.
/// </summary>
[Guid("f0a50f9b-7c7f-4d90-8fc2-15d5d34a3a9f"), ComVisible(true)]
[SwAddin(
    Description = "SwCSharpAddin1 description",
    Title = "SwCSharpAddin1",
    LoadAtStartup = true

Fluff : You may fill your assembly information in the Project Properties/Application/AssemblyInformation. For the GUID part, you may use this site. Don't take the same GUID as in the code section, they must be different. If I may share with you my way of giving version numbers : YY.MM.DD.VV as in (Year.Month.Day.Incremental version for the day)

3. Debugging your Addin

In the project Properties/Debug section, you should already have "Start External Program" checked with your Solidworks path. If so, you are now able to debug your application. You can find an example here . You can place a breakpoint inside the CreateCube function and you'll hit it as soon are you click the option in Solidworks.

NOTE : I don't include any code here. I'd rather have you start from the template. Much easier to understand.