Hide Table of Contents

Calling Add-ins (VB.NET)

This sample shows how to implement IEdmAddIn5::GetAddInInfo and IEdmAddIn5::OnCmd to create a Visual Basic add-in that is called when the user clicks a button in a file data card. The add-in opens a dialog box in which the user browses for the file whose data card is displayed. The add-in copies the path of the selected file to a text field in the file's data card. 

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. Follow Creating Menu Commands (VB.NET) to create a basic add-in.

  2. Register a hook to notify your add-in when a user clicks a button in a file data card. 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 information to display in the add-in's Properties dialog box
         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

         'Notify the add-in when a file data card button is clicked
         poCmdMgr.AddHook(EdmCmdType.EdmCmd_CardButton)

    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
      On Error GoTo ErrHand

        'Respond only to a specific button command
        'The button command to respond to begins with "MyButton:" and ends with the name of the
        'variable to update in the card
        If Left(poCmd.mbsComment, 9) = "MyButton:" Then
          'Get the name of the variable to update.
          Dim VarName As String
          VarName = Right(poCmd.mbsComment, Len(poCmd.mbsComment) - 9)

          'Let the user select the file whose path will be copied to the card variable
          Dim vault As EdmVault5
          vault = poCmd.mpoVault
          Dim PathList As IEdmStrLst5
          PathList = vault.BrowseForFile(poCmd.mlParentWnd, EdmBrowseFlag.EdmBws_ForOpen + EdmBrowseFlag.EdmBws_PermitVaultFiles, "", "", "", "", "Select File for " + VarName)

             If Not PathList Is Nothing Then
               Dim path As String
               path = PathList.GetNext(PathList.GetHeadPosition) 

               'Store the path in the card variable 
               Dim vars As IEdmEnumeratorVariable5 
               vars = poCmd.mpoExtra 
               Dim VariantPath As Object 
               VariantPath = path 
               vars.SetVar(VarName, "", VariantPath) 
             End If
           End If

           Exit Sub

         'Handle errors
         ErrHand:
           Dim ErrVault As EdmVault5
           ErrVault = poCmd.mpoVault
           Dim ErrName As String
           Dim ErrDesc As String
           ErrVault.GetErrorString(Err.Number, ErrName, ErrDesc)
           ErrVault.MsgBox(poCmd.mlParentWnd, "Error in my card button." + vbLf + ErrDesc)

    End Sub

    The second argument to OnCmd, ppoData, is an array of EdmCmdData structures. There is one element in the array when it is called from the file data card. See EdmCmdData for information about the structure.

  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 Professional 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 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. Click Cards > File Cards.

  9. Double-click Text Card.

  10. Add a button to the card.

  11. Click the button.

  12. In Caption, type Browse....

  13. In Command type, select Run Add-in.

  14. In Name of add-in, type MyButton:Title.

  15. Save the card and exit the Card Editor.

  16. Open Windows Explorer on the vault and select a checked-out text file.

  17. Click Browse in the file's data card.

  18. The Select File for Title dialog box pops up.

  19. Browse to and select the checked-out text file.

  20. Click Open to copy the path of the selected file to the Title field of the file's data card.

Remarks

In this example, the value of a variable is set using IEdmEnumeratorVariable5::SetVar. You can also read values using IEdmEnumeratorVariable5::GetVar.

Using a button handler like this add-in, you can also:

  • Retrieve the number of configurations, layouts, or both, in the file by inspecting the EdmCmdData::mpoExtra variable, which contains IEdmStrLst5 of file interfaces.

  • Switch the active configuration.

  • Set focus to a certain control using the members of EdmCmdData.

  • Close the card automatically after the button handler returns by setting the EdmCmdData::mlLongData1 variable to one of the EdmCardFlag constants. 



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:   Calling 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.