Hide Table of Contents

Calling Add-ins (C#)

This sample shows how to implement IEdmAddIn5::GetAddInInfo and IEdmAddIn5::OnCmd to create a Visual C# 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 (C#) 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 void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
    {
           //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);
    }

  4. Implement IEdmAddIn5::OnCmd as follows:
     

         public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)
         {
                //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 (Strings.Left(poCmd.mbsComment, 9) == "MyButton:")
                {
                    //Get the name of the variable to update. 
                    string VarName = null;
                    VarName = Strings.Right(poCmd.mbsComment, Strings.Len(poCmd.mbsComment) - 9);
     
                    //Let the user select the file whose path will be copied to the card variable
                    EdmVault5 vault = default(EdmVault5);
                    vault = (EdmVault5)poCmd.mpoVault;
                    IEdmStrLst5 PathList = default(IEdmStrLst5);
                    PathList = vault.BrowseForFile(poCmd.mlParentWnd, (int)EdmBrowseFlag.EdmBws_ForOpen + (int)EdmBrowseFlag.EdmBws_PermitVaultFiles, """""""""Select File for " + VarName);
     
                    if ((PathList != null))
                    {
                        string path = null;
                        path = PathList.GetNext(PathList.GetHeadPosition());
     
                        //Store the path in the card variable 
                        IEdmEnumeratorVariable5 vars = default(IEdmEnumeratorVariable5);
                        vars = (IEdmEnumeratorVariable5)poCmd.mpoExtra;
                        object VariantPath = null;
                        VariantPath = path;
                        vars.SetVar(VarName, "", VariantPath);
                    }
                }
     
                return;
         }

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

  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 (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) 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.