Hide Table of Contents

Creating Menu Commands (VB.NET)

This topic shows how to create an add-in using VB.NET in Microsoft Visual Studio 2010 that adds menu commands to the context-sensitive and Tools menus of vaults in Windows Explorer.


NOTE: Because SOLIDWORKS PDM Professional 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 Visual Studio 2010.

  2. Click File > New > Project.

  3. Select Visual Basic in Installed Templates and Class Library as the template.

  4. Type a name for the project in Name and click OK.

  5. Click Project > Add Reference > COM, click PDMWorks Enterprise version Type Library, and click Add.

  6. Click Project > Add Reference > .NET, click System.Drawing, and click Add.

  7. Click Close.

  8. Right-click the name of the 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.

  9. Save the project.

  10. Double-click Class1.vb in the Solution Explorer to open the code window.

    1. Before Public Class Class1 type:

      Imports EdmLib
      Imports System.Runtime.InteropServices
      <Guid("")> _
      <ComVisible(True)> _

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

    3. Type Implements IEdmAddIn5 after Public Class Class1 and make sure that the GetAddInInfo and OnCmd methods are generated after you press Enter.

    4. Replace your add-in's implementation of the IEdmAddIn5::GetAddInInfo method with the following code:

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

      'Specify the add-in information 
      poInfo.mbsAddInName = "Menu command sample"
      poInfo.mbsCompany = "SOLIDWORKS Corporation"
      poInfo.mbsDescription = "Adds menu command items"
      poInfo.mlAddInVersion = 1
      poInfo.mlRequiredVersionMajor = 5
      poInfo.mlRequiredVersionMinor = 2

      'Add menu command items (the command-ID numbers 1000 and 1001 are
      'arbitrary; PDM does not use them; instead, PDM only passes them to the
      'implementation of OnCmd to know which command was selected)

      poCmdMgr.AddCmd(1000, "First command", EdmMenuFlags.EdmMenu_Nothing, "This is the first command", "First command", 0, 99)
      poCmdMgr.AddCmd(1001, "Second command", EdmMenuFlags.EdmMenu_MustHaveSelection, "This is the second command", "Second command", 1, 99)

    End Sub

    The flag
    EdmMenuFlags.EdmMenu_MustHaveSelection means that the second command is only available if the user has selected one or more files or folders.

    1. Replace your add-in's implementation of the IEdmAddIn5::OnCmd method with the following code (IEdmAddIn5::OnCmd is called when a menu command is selected by the user):

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

      'Check the command ID to see which command was selected
      '(This only affects the caption of the message box below)
    Dim CommandName As String

      If poCmd.mlCmdID = 1000 Then
        CommandName = "The first command."

        CommandName = "The second command."

      End If

      'Retrieve the bounds of the array containing the selected files and folders
    Dim index As Long

      Dim last As Long

      index = LBound(ppoData)

      last = UBound(ppoData)

      Dim StrID As String

      'Create a message showing the names and IDs of all selected files and folders

      Dim message As String

      message = "You have selected the following files and folders: " + vbLf

      While index <= last
        If ppoData(index).mlObjectID1 = 0 Then
          message = message + "Folder: (ID="

          StrID = ppoData(index).mlObjectID2

          message = message + StrID + ") "
            message = message + "File: (ID="

            StrID = ppoData(index).mlObjectID1

            message = message + StrID + ") "
        End If

        message = message + ppoData(index).mbsStrData1 + vbLf
        index = index + 1
      End While

      'Display the message
      Dim v As EdmVault5
      v = poCmd.mpoVault
      v.MsgBox(poCmd.mlParentWnd, message, EdmMBoxType.EdmMbt_OKOnly, CommandName)

    End Sub

  11. Click Build > Build Solution to build the add-in.

  12. Install the add-in through the SOLIDWORKS PDM Professional Administration tool:
    1. Open the SOLIDWORKS PDM Professional 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 click New Add-in.
    4. Browse to project_path\project_name\project_name\bin\Debug, click project_name.dll and Interop.EdmLib.dll.
    5. Click Open.
    6. Click OK.
    7. Click OK.


  13. The first menu command appears in the context-sensitive and Tools menus of vault files in Windows Explorer. The second menu command appears in the context-sensitive menus only when one or more files or folders are selected. Right-click a file in the vault and select Second command. A dialog similar to the following is displayed:


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

Subject:   Feedback on Help Topics
Page:   Creating Menu Commands (VB.NET)
*   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:


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

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.