Hide Table of Contents

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

NOTE: Because SOLIDWORKS PDM Professional cannot force a reload of add-ins if they are written in VB.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 Basic > Class Library.
     
  3. Type the name of your project in Name.
     
  4. Click Browse and navigate to the folder where to create your project.
     
  5. Click OK.

    Class1.vb containing an empty class called Class1 is created.
     
  6. Right-click the name of your project in the Solution Explorer to add the SOLIDWORKS PDM Professional type library and the Systems.Windows.Forms assembly:
     
    1. Select Add Reference.
       
    2. Click COM, select PDMWorks Enterprise 20nn Type Library, and click Add.
       
    3. Select Add Reference.
       
    4. Click .NET, select System.Windows.Forms, and click Add.
       
    5. Click Close.
  7. Type Imports System.Windows.Forms at the top of the code window.
     
  8. Type Imports EdmLib  and Imports System.Runtime.InteropServices below Imports System.Windows.Forms.
     
  9. Type before Public Class Class1:
    <Guid("")> _
    <ComVisible(True)> _

     
  10. To populate the GUID attribute above, click Tools > Create GUID in the IDE, select GUID Format 6, click Copy, and click Exit. Replace <Guid("")> with the copied string.
     
  11. Type below Public Class Class1:
    Implements IEdmAddIn5
     
  12. Implement IEdmAddIn5::GetAddInInfo by pasting the following code between Implements IEdmAddIn5 and End Class:

Public Sub GetAddInInfo(ByRef poInfo As EdmAddInInfo, ByVal poVault As IEdmVault5, ByVal poCmdMgr As IEdmCmdMgr5) Implements IEdmAddIn5.GetAddInInfo

      ' Specify add-in information

      poInfo.mbsAddInName = "VB.NET Add-in"

      poInfo.mbsCompany = "My Company"

      poInfo.mbsDescription = "Menu add-in that shows a message box."

      poInfo.mlAddInVersion = 1

 

      ' Specify minimum version of SOLIDWORKS PDM Professional

      poInfo.mlRequiredVersionMajor = 6

      poInfo.mlRequiredVersionMinor = 4

 

      ' Register a menu command

      poCmdMgr.AddCmd(1, "VB.NET Add-in", EdmMenuFlags.EdmMenu_Nothing)

 

   End Sub

  1. Implement IEdmAddIn5::OnCmd by pasting the following code between End Sub and End Class:

    NOTE: IEdmVault8::GetWin32Window is used to convert the parent window handle to a window handle that .NET can use
    .

Public Sub OnCmd(ByRef poCmd As EdmCmd, ByRef ppoData As System.Array) Implements IEdmAddIn5.OnCmd

 

      ' Handle the menu command

      If poCmd.meCmdType = EdmCmdType.EdmCmd_Menu Then

         If poCmd.mlCmdID = 1 Then

            Dim v8 as IEdmVault8

            V8 = poCmd.mpoVault

            System.Windows.Forms.MessageBox.Show(v8.GetWin32Window(poCmd.mlParentWnd), "VB.NET Add-in")

         End If

      End If

 

   End Sub

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

Imports System.Windows.Forms
 

' Wrapper class to use SOLIDWORKS PDM Professional as a parent window to VB forms

Public Class WindowHandle

   Implements IWin32Window

   Private mHwnd As IntPtr

 

   Public Sub New(ByVal hWnd As Integer)

      mHwnd = New IntPtr(hWnd)

   End Sub

   Public ReadOnly Property Handle() As IntPtr Implements System.Windows.Forms.IWin32Window.Handle

      Get

         Return mHwnd

      End Get

   End Property

End Class

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.vb.
 

  1. Right-click the name of your project in the Solution Explorer and select Properties.
     
    1. On the Application tab, click Assembly Information.
       
    2. De-select Make assembly COM-Visible.
       
    3. On the Compile tab, select Register for COM interop.
       
  2. Change your add-in to be a Debug Add-in:
     
    1. Right-click the name of your project in the Solution Explorer and select Properties.
       
    2. Click the Debug tab.
       
    3. Click Start external program and type C:\Windows\System32\notepad.exe in the text field.

       
  1. Right-click EdmLib in the Solution Explorer, select Properties, and set Embed Interop Types to False in the Properties window to handle methods that pass arrays of structures.
     
  2. If creating this add-in on a 64-bit computer, edit project_path\project_name\project_name\project_name.vbproj 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.
       
  3. Right-click the name of your project in the Solution Explorer and select Properties.
     
  4. Click Advanced Compile Options on the Compile tab.
     
  5. Select .NET Framework 2.0 in the Target framework (all configurations) dropdown.
     
  6. Click Build > Build Solution to build the add-in.
     
  7. Install the add-in as a Debug Add-in using the SOLIDWORKS PDM Professional Administration tool:
     
    1. Start up the SOLIDWORKS PDM Professional Administration tool.
       
    2. Expand the vault where you want to install this add-in. Log in if prompted.
       
    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, select project_name.dll, and click Open.

      Your add-in's name, path, and class ID should appear in Add-ins installed for debugging on this machine.
       
    5. Click OK.
       
  8. In Microsoft Visual Studio 2010, click Debug > Start Debugging or press F5.
     
  9. Click File > Open in Notepad.
     
  10. Click the name of the vault where you installed your add-in.
     
  11. Right-click inside the vault in Windows Explorer and select VB.NET Add-in.

    A message box is displayed with the message VB.NET Add-in.
     
  12. Click OK to close the message box.

 

Complete Source Code

'Class1.vb

Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports EdmLib
 
<Guid("")> _   ' See step 10 above to create the GUID
<ComVisible(True)> _
Public Class Class1
    Implements IEdmAddIn5
 
    Public Sub GetAddInInfo(ByRef poInfo As EdmAddInInfoByVal poVault As IEdmVault5ByVal poCmdMgr As IEdmCmdMgr5Implements IEdmAddIn5.GetAddInInfo
        ' Fill in the add-in's description
        poInfo.mbsAddInName = "VB.NET Add-in"
        poInfo.mbsCompany = "My Company"
        poInfo.mbsDescription = "Menu add-in that shows a message box."
        poInfo.mlAddInVersion = 1
 
        ' Minimum SOLIDWORKS PDM Professional version needed for VB.NET add-ins is 6.4
        poInfo.mlRequiredVersionMajor = 6
        poInfo.mlRequiredVersionMinor = 4
 
        ' Register a menu command
        poCmdMgr.AddCmd(1, "VB.NET Add-in"EdmMenuFlags.EdmMenu_Nothing)
 
    End Sub
 
    Public Sub OnCmd(ByRef poCmd As EdmCmdByRef ppoData As System.ArrayImplements IEdmAddIn5.OnCmd
 
        ' Handle the menu command
        If poCmd.meCmdType = EdmCmdType.EdmCmd_Menu Then
            If poCmd.mlCmdID = 1 Then
                Dim v8 As IEdmVault8
                v8 = poCmd.mpoVault
                System.Windows.Forms.MessageBox.Show(v8.GetWin32Window(poCmd.mlParentWnd), "VB.NET Add-in")
            End If
        End If
 
    End Sub
 
End Class

'WindowHandle.vb

Imports System.Windows.Forms
 
Public Class WindowHandle
    Implements IWin32Window
    Private mHwnd As IntPtr
 
    Public Sub New(ByVal hWnd As Integer)
        mHwnd = New IntPtr(hWnd)
    End Sub
    Public ReadOnly Property Handle() As IntPtr Implements System.Windows.Forms.IWin32Window.Handle
        Get
            Return mHwnd
        End Get
    End Property
End Class

 



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 (VB.NET)
*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) 2018 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.