Hide Table of Contents

Creating Serial Numbers (VB.NET)

This sample shows how to generate serial numbers for file data cards using an add-in written in VB.NET.


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

  • SOLIDWORKS PDM Professional recommends that serial numbers be generated using the built-in format strings or lists. They provide better performance than serial numbers generated by add-ins or serial numbers from files. Only write an add-in to generate the serial number if built-in format strings or lists are insufficient.  

  • The differences between serial number generation and other types of hooks are:

  1. Follow Creating Menu Commands (VB.NET) to create a basic add-in.

  2. Register a hook to notify your add-in when a serial number needs to be generated. Implement IEdmAddIn5::GetAddInInfo as follows:

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

      'Specify add-in information
      poInfo.mbsAddInName = "My serial number generator"
      poInfo.mbsCompany = "The name of my company"
      poInfo.mbsDescription = "Implements serial numbers"
      poInfo.mlAddInVersion = 1
      poInfo.mlRequiredVersionMajor = 5
      poInfo.mlRequiredVersionMinor = 2

      'Register that a serial number needs to be generated

    End Sub

  4. Implement IEdmAddIn5::OnCmd as follows:

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

      'Check the upper and lower bounds of the array
      Dim index As Long index = LBound(ppoData)
      Dim last As Long last = UBound(ppoData)

      If index <= last Then
        Dim cnt As Integer
        cnt = last - index + 1

        'Create a temporary array to which you have full access
        Dim tmpArr(cnt) As EdmCmdData
        tmpArr = ppoData

        'Generate serial numbers for all of the affected files
        Dim CounterVal As String

        While index <= last
          CounterVal = tmpArr(index).mlLongData1
          Dim s As String
          s = "My serno(" + CounterVal + ")"
          tmpArr(index).mbsStrData1 = s
          index = index + 1
        End While

        'Return the updated data
        ppoData = tmpArr
      End If

    End Sub

    The second argument to OnCmd is an array of EdmCmdData structures. There is one element in the array for each file that is affected by the call. See EdmCmdData for a complete list of members and their descriptions.

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

  7. 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.
  8. Right-click the Serial Numbers node in the tree and click New Serial Number.

  9. Create a new serial number in the Name field and select Serial number from add-in in the Type dropdown.

    The name of your add-in is displayed in Name of add-in.

  10. After ensuring that your add-in is selected, click OK.

    Now you can connect the add-in serial number to controls in your file data cards.

  11. Click Cards > File Cards, double-click Text Card, and click the Title control.

  12. In the Default value group box on the Edit-box properties panel, click Serial number and select the serial number that you created in step 7.


  14. Save the card and exit the Card Editor.

  15. Create a new text file by right-clicking in a Windows Explorer vault view and clicking New > Text Document.

    The file data card displays a serial number in Title of the newly added file.

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 Serial Numbers (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.