Hide Table of Contents

Notify User When File Changes State Example (VB.NET)

This example shows how to create an add-in that pops up a message box when a file is approved.

'--------------------------------------------------------------------------------------
' Preconditions:
' 1. Start Microsoft Visual Studio 2010.
' 2. Click File > New > Project > Visual Basic > Class Library.
' 3. Select .NET Framework 2.0 in the dropdown at the top of the dialog.
' 4. Type StateChangeNotificationAddin in Name.
' 5. Click Browse and navigate to the folder where to create the project.
' 6. Click OK
' 7. Right-click the project name in the Solution Explorer and click Add Reference
' 8. In the Add Reference dialog:   

'    a. Add PDMWorks Enterprise PDM Type Library as a reference (click COM in the
'       left-side panel, click PDMWorks Enterprise nnnn Type Library
'       and click Add).

'    b. Add System.Windows.Forms as a reference (click Assemblies > Framework in the
'       left-side panel, click System.Windows.Forms, and click Add).
'    c. Click Close.
' 9. Right-click the project name in the Solution Explorer and click Properties.
'10. In the Properties window:
'    a. Click Application > Assembly Information.
'    b. Select Make assembly COM-Visible.
'    c. Click OK.
'11. Copy the code below to Class1.vb.

'12. Click Build > Build Solution.
'
' Postconditions: 
' 1. Open the SOLIDWORKS Enterprise PDM Administration tool, expand a vault_name node,
'    and log in as Admin.

' 2. Ensure that Default Workflow exists under vault_name > Workflows.
'    a. Ensure that the workflow has an Approved state.
'    b. Ensure that the workflow has a Change Approved transition.

' 3. Under vault_name, right-click Add-ins and click New Add-in.
'    a. Navigate to the
bin\Debug directory of your built project.
'    b. Click Interop.EdmLib.dll and StateChangeNotificationAddin.dll
'    c. Click Open.

'    d. Click OK.
' 4. Click OK after reading the SOLIDWORKS Enterprise PDM warning dialog.
' 5. Open Windows Explorer on a view of vault_name and:
'    a. Log in as Admin.
'    b. Create a new file in the root directory of vault_name and check it in.
'    c. Right-click the file and click Change State > transition.
'    d. Click OK in the Do Transition dialog.
'    e. Repeat steps c and d until the file is in a state that it can be Approved.
'    g. Right-click the file and click Change State > Change Approved.
'    h. Click OK in the Do Transition dialog.
' 6. A message box pops up notifying the user whether the file changing state is a
'    top node. Click OK.

' 7. A message box pops up notifying the user that the file has been approved. 
'    Click OK.
'---------------------------------------------------------------------------------------
Imports System.Windows.Forms
Imports EdmLib
 
Public Class ChangeStateNotification
    Implements IEdmAddIn5
 
    Public Sub GetAddInInfo(ByRef poInfo As EdmLib.EdmAddInInfoByVal poVault As EdmLib.IEdmVault5ByVal poCmdMgr As EdmLib.IEdmCmdMgr5Implements EdmLib.IEdmAddIn5.GetAddInInfo
 
 
        Try
            poInfo.mbsAddInName = "VB.NET Add-In"
            poInfo.mbsCompany = "Dassault Systemes"
            poInfo.mbsDescription = "Exercise demonstrating responding to a change state event."
            poInfo.mlAddInVersion = 1
 
            'Minimum SOLIDWORKS Enterprise PDM version
            'needed for VB.Net Add-Ins is 6.4
            poInfo.mlRequiredVersionMajor = 6
            poInfo.mlRequiredVersionMinor = 4
 
            'Register to receive a notification when
            'a file has changed state
            poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostState)
        Catch ex As Runtime.InteropServices.COMException
            MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
 
    Public Sub OnCmd(ByRef poCmd As EdmLib.EdmCmdByRef ppoData As System.ArrayImplements EdmLib.IEdmAddIn5.OnCmd
 
        Try
            Dim AffectedFile As EdmCmdData
            Dim AffectedFileNames As String = ""
           
Dim cmdNode As IEdmCmdNode
            Dim
 topNode As Boolean
            Select Case poCmd.meCmdType
                'A file has changed state
                Case EdmCmdType.EdmCmd_PostState
                    For Each AffectedFile In ppoData
                        If AffectedFile.mbsStrData2 = "Approved" Then
                            AffectedFileNames += AffectedFile.mbsStrData1 + vbCrLf
                        End If

                        cmdNode = AffectedFile.mpoExtra
                        topNode = cmdNode.GetProperty(EdmCmdNodeProp.EdmCmdNode_IsTopNode)
                        MessageBox.Show("File changing state is a top node? " + topNode)


                    Next AffectedFile
 
                    If AffectedFileNames.Length > 0 Then
                        poCmd.mpoVault.MsgBox(poCmd.mlParentWnd, AffectedFileNames + " has been approved.")
                    End If
 
                    'The event isn't registered
                Case Else
                    poCmd.mpoVault.MsgBox(poCmd.mlParentWnd"An unknown command type was issued.")
            End Select
        Catch ex As Runtime.InteropServices.COMException
            MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class

 

 

 



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:   Notify User When File Changes State Example (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) 2015 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.