SOLIDWORKS PDM Professional API Help

Creating Serial Numbers (C#)

This sample shows how to generate serial numbers for file data cards using an add-in written in Visual C#.

NOTES:

  1. Follow Creating Menu Commands (C#) 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:

    public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
    {
           //Return information about this add-in to the Administrate Add-ins dialog
           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 that a serial number needs to be generated
           poCmdMgr.AddHook(EdmCmdType.EdmCmd_SerialNo);
    }

  3. Implement IEdmAddIn5::OnCmd as follows:

  4. public void OnCmd(ref EdmCmd poCmd, ref EdmCmdData[] ppoData)
    {
           //Check the upper and lower bounds of the array 
           int Index = ppoData.GetLowerBound(0);
           int last = ppoData.GetUpperBound(0);
     
           if (Index <= last) {
               int cnt; 
               cnt = last - Index + 1 ;
     
               //Create a temporary array to which you have full access
               EdmCmdData[] tmpArr; 
               tmpArr = (EdmCmdData[])ppoData; 
     
               //Generate serial numbers for all of the affected files 
               String CounterVal; 
     
               while (Index <= last) {
                   CounterVal = tmpArr[Index].mlLongData1.ToString() ;
                   String s;
                   s = "My serno(" + CounterVal + ")" ;
                        tmpArr[Index].mbsStrData1 = s ;
                        Index = Index + 1 ;
               }
     
               //Return the updated data 
                ppoData = tmpArr;
           }
    }


    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.

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

  6. 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 EPDM.Interop.epdm.dll.
       
    5. Click Open.
       
    6. Click OK.
       
    7. Click OK.
  7. Right-click the Serial Numbers node in the tree and click New Serial Number.

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

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

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

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

  12.     

  13. Save the card and exit the Card Editor.

  14. Create a new text file by right-clicking in a File Explorer vault view and clicking New > Text File.

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