Hide Table of Contents

This topic shows how to create a debug add-in using Visual C# in Microsoft Visual Studio 2010.

NOTE: Because SolidWorks Enterprise PDM cannot force a reload of add-ins if they are written in .NET, all client machines must be restarted to ensure that the latest version of the add-in is used.

  1. Start Microsoft Visual Studio 2010.
     
  2. Click File > New > Project > Visual C# > Class Library.
     
  3. Select .NET Framework 2.0 in the dropdown at the top of the dialog.
     
  4. Type the name of your project in Name.
     
  5. Click Browse and navigate to the folder where to create your project.
     
  6. Click OK.

    Class1.cs containing empty class, Class1, is created.
     
  7. Right-click the project name in the Solution Explorer and click Add Reference.
     
    1. Click COM in the left-side panel, click PDMWorks Enterprise 20nn Type Library, and click Add.
       
    2. Click Assemblies > Framework in the left-side panel, click System.Windows.Forms, and click Add.
       
    3. Click Close.
  8. Right-click the project name in the Solution Explorer and click Properties.
     
    1. Click Application > Assembly Information.
       
    2. Click Make assembly COM-Visible to register the add-in.
       
    3. Click OK.
  9. Make this a Debug Add-in:
     
    1. Click the Debug tab.
       
    2. Click Start external program and type C:\Windows\System32\notepad.exe in the text field.

     

  10. If creating this add-in on a 64-bit computer, edit project_path\project_name\project_name\project_name.csproj in Notepad:
     
    1. Insert the following line below <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> and below  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">.

      <PlatformTarget>AnyCPU</PlatformTarget>
       
    2. Save the file and exit Notepad.
     
  11. Double-click Class1.cs in the Solution Explorer to open the code window.
     
  12. At the top of the code window, type:

    using System.Windows.Forms;
    using EdmLib;
     
  13. Replace:

  14. public class Class1

     with:
     

    public class Class1 : IEdmAddIn5

  15. In the code, right-click IEdmAddIn5 and click Implement Interface > Implement Interface.
     
  16. Implement IEdmAddIn5::GetAddInInfo as follows:
     

        public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
        {
            //Specify information to display in the add-in's Properties dialog box
            poInfo.mbsAddInName = "C# Add-in";
            poInfo.mbsCompany = "My Company";
            poInfo.mbsDescription = "Menu add-in that shows a message box.";
            poInfo.mlAddInVersion = 1;
     
            //Specify the minimum required version of SolidWorks Enterprise PDM
            poInfo.mlRequiredVersionMajor = 6;
            poInfo.mlRequiredVersionMinor = 4;
     
            // Register a menu command
            poCmdMgr.AddCmd(1, "C# Add-in", (int)EdmMenuFlags.EdmMenu_Nothing);
     
        }

  17. Implement IEdmAddIn5::OnCmd as follows:
  18. public void OnCmd(ref EdmCmd poCmd, ref System.Array ppoData)
        {
     
            // Handle the menu command
            if (poCmd.meCmdType == EdmCmdType.EdmCmd_Menu)
            {
                if (poCmd.mlCmdID == 1)
                    System.Windows.Forms.MessageBox.Show("C# Add-in");
                }
            }
        }

  19. Implement your own window handle wrapper by right-clicking the project name in the Solution Explorer and clicking Add > Class:
     
    1. Type WindowHandle.cs in Name.
       
    2. Click Add.
       
    3. Replace the code in the code window with the following code.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
     
    namespace Addin_CSharp
    {
        //Wrapper class to use SolidWorks Enterprise PDM as the parent window
        class WindowHandle : IWin32Window
        {
            private IntPtr mHwnd;
     
            public WindowHandle(int hWnd)
            {
                mHwnd = new IntPtr(hWnd);
            }
            public IntPtr Handle
            {
                get { return mHwnd; }
            }
        }
    }

    Your add-in uses the new wrapper in the menu command handler to show the message box by calling System.Windows.Forms.MessageBox.Show in Class1::OnCmd in Class1.cs.

  20. Click Build > Build Solution to build the add-in.
     
  21. Install the add-in for debugging through the SolidWorks Enterprise PDM Administration tool:
     
    1. Open the SolidWorks Enterprise PDM Administration tool.
       
    2. Expand the vault where you want to install this add-in and log in as Admin.
       
    3. Right-click Add-ins and select Debug Add-ins.
       
    4. Click Add Add-in, browse to project_path\project_name\project_name\bin\Debug, click project_name.dll, and click Open.

      Your add-in's name, path, and class ID should appear in the Add-ins installed for debugging on this machine list.
       
    5. Click OK.
       
  22. In Microsoft Visual Studio 2010, click Debug > Start Debugging or press F5.
     
  23. Open Notepad and click File > Open.
     
  24. In the Open dialog, click the name of the vault where you installed this add-in.
     
  25. Right-click inside the vault view and click C# Add-in.

    Displays the message, C# Add-in.
     
  26. Click OK to close the message box.
     
  27. Click Cancel.
     
  28. Close Notepad.

    Complete Source Code

    Class1.cs

    using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    using System.Windows.Forms;
    using EdmLib;
     
     
    public class Class1 : IEdmAddIn5
    {
     
        public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
        {
            
            poInfo.mbsAddInName = "C# Add-in";
            poInfo.mbsCompany = "My Company";
            poInfo.mbsDescription = "Menu add-in that shows a message box.";
            poInfo.mlAddInVersion = 1;

            poInfo.mlRequiredVersionMajor = 6;
            poInfo.mlRequiredVersionMinor = 4;
     
            poCmdMgr.AddCmd(1, "C# Add-in", (int)EdmMenuFlags.EdmMenu_Nothing);
     
        }
     

    public void OnCmd(ref EdmCmd poCmd, ref System.Array ppoData)
        {
     
            
            if (poCmd.meCmdType == EdmCmdType.EdmCmd_Menu)
            {
                if (poCmd.mlCmdID == 1)
                {
                    System.Windows.Forms.MessageBox.Show("C# Add-in");
                }
            }
        }
    }

    WindowHandle.cs

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
     
    namespace Addin_CSharp
    {
        class WindowHandle : IWin32Window
        {
            private IntPtr mHwnd;
     
            public WindowHandle(int hWnd)
            {
                mHwnd = new IntPtr(hWnd);
            }
            public IntPtr Handle
            {
                get { return mHwnd; }
            }
        }
    }



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:   Creating Add-ins (C#)
*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) 2014 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.