Hide Table of Contents

Create a Task that Finds Approved Files Example (VB.NET)

This example shows how to create a task add-in that notifies the logged-in user as to which files in the vault are in the Approved state.

' 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 TaskAddinExample 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 the SOLIDWORKS PDM Professional 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. On the Application tab, click Assembly Information.
'    b. De-select Make assembly COM-Visible.
'    c. On the Compile tab, click Register for COM interop.
'11. Save the project.
'12. Copy the code below to Class1.vb.
To populate the GUID attribute, click Tools > Create GUID in the IDE,
'    select GUID Format 6, click Copy, and click Exit. Replace <
Guid("")> with the
'    copied string.

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

'  2. Ensure that Default Workflow with an Approved state exists 
'     under vault_name > Workflows.

'  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 TaskAddinExample.dll.
'     c. Click Open.

'     d. Click OK.
'  4. Click OK after reading the SOLIDWORKS PDM Professional warning dialog.
'  5. In the taskbar notification area:
'     a. Click the SOLIDWORKS PDM icon.
'     b. Click Task Host Configuration.
'     c. Select vault_name in the File Vault dropdown.
'     d. Select Permit next to the add-in you installed in step 3.
'     e. Click OK.

'  6. In the Administration tool under vault_name, right-click Tasks and click New Task.
'     a. Type Approved Files Task in the upper-left text box.
'     b. Select the VB.NET Task Add-in from the Add-in dropdown.
'     c. When the attach debugger message box appears:
'        1. In the IDE, click Debug > Attach to Process > ConisioAdmin.exe.
'        2. Click Attach.
'        3. Click OK to close the message box.
'     d. Click Next.
'     e. On the Execution Method properties page, select the local computer.
'     f. Click Next.
'     g. On the Scheduling properties page, select This task is not scheduled.
'     h. Click Next.
'     i. On the Permissions property page, select Admin.
'     j. Click Next.
'     k. On the Success Notification property page:
'        1. Select Notify the user who launched the task.
'        2. In the Subject field, type Success.
'        3. In the Text field, type The task successfully completed at, type a space,
'           click >, and click Current Time.

'     l. Click OK to close the New Task dialog.
'  7. Expand vault_name > Tasks and double-click Task List.
'  8. Click Add Task
'  9. In the Add Task dialog:

'     a. Select Approved Files Task from the dropdown.
'     b. Click OK.
' 10. When the attach debugger message box appears:
'     a. In the IDE, click Debug > Attach to Process > TaskExecutor.exe.
'     b. Click Attach.
'     c. Click OK to close the message box.
' 11. The task appears in the Pending tasks list. Observe the task status.
' 12. When the task completes, the task moves to the Completed tasks
'     list. The logged-in user receives a notification with the list of approved files.

Imports EdmLib
Imports System.Runtime.InteropServices

Public Class TaskAddinExample
    Implements IEdmAddIn5
    Public Sub GetAddInInfo( _
      ByRef poInfo As EdmLib.EdmAddInInfo, _
      ByVal poVault As EdmLib.IEdmVault5, _
      ByVal poCmdMgr As EdmLib.IEdmCmdMgr5) _
      Implements EdmLib.IEdmAddIn5.GetAddInInfo
            poInfo.mbsAddInName = _
              "VB.NET Task Add-In"
            poInfo.mbsCompany = "Dassault Systemes"
            poInfo.mbsDescription = _
              "Exercise demonstrating a task that lists " _
              + "files in the Approved state."
            poInfo.mlAddInVersion = 1
            'Minimum SOLIDWORKS PDM Professional version
            'needed for VB.Net Task Add-Ins is 10.0
            poInfo.mlRequiredVersionMajor = 10
            poInfo.mlRequiredVersionMinor = 0
            'Register this add-in as a task add-in
            'Register this add-in to be called when
            'selected as a task in the Administration tool
        Catch ex As Runtime.InteropServices.COMException
            MsgBox("HRESULT = 0x" + _
              ex.ErrorCode.ToString("X") + vbCrLf + _
        Catch ex As Exception
        End Try
    End Sub
    Public Sub OnCmd(ByRef poCmd As EdmLib.EdmCmd, _
      ByRef ppoData As System.Array) _
      Implements EdmLib.IEdmAddIn5.OnCmd
            Select Case poCmd.meCmdType
                Case EdmCmdType.EdmCmd_TaskRun
                    OnTaskRun(poCmd, ppoData)
                Case EdmCmdType.EdmCmd_TaskSetup
                    OnTaskSetup(poCmd, ppoData)
            End Select
        Catch ex As Runtime.InteropServices.COMException
            MsgBox("HRESULT = 0x" + _
              ex.ErrorCode.ToString("X") + vbCrLf + _
        Catch ex As Exception
        End Try
    End Sub
    Private Sub OnTaskRun(ByRef poCmd As EdmCmd, _
      ByRef ppoData As System.Array)
        'Get the task instance interface
        Dim inst As IEdmTaskInstance
        inst = poCmd.mpoExtra
            'Keep the task list status up to date
            inst.SetStatus _
            'Format a message that will be displayed
            'in the task list
            inst.SetProgressRange(10, 1, "Task is running.")
            Dim Items As List(Of EdmSelItem2) = _
              New List(Of EdmSelItem2)
            inst.SetProgressPos(4, "Task is searching.")
            Dim Search As IEdmSearch6 = _
            If Search Is Nothing Then Return
            Search.SetToken( _
            Search.SetToken( _
              EdmSearchToken.Edmstok_WorkflowName, _
              "Default Workflow")
            Search.SetToken( _

            'Uncomment and modify the following lines to look for files
            'that have a card variable with values in a specific range

            'Dim varName1 As Object = "Card_Variable_ID_or_Name"
            'Dim varValue1 As Object = "Card_Variable_Value_1"
            'Dim varOp1 as Integer = EdmVarOp_NumberGreaterThan
            'Dim varValue2 As Object = "Card_Variable_Value_2"
            'Dim varOp2 as Integer = EdmVarOp_NumberLessThan
               'Search.AddVariable2(varName1, varValue1, varOp1)
               'Search.AddVariable2(varName1, varValue2, varOp2)

            Dim SearchResult As IEdmSearchResult5 = _
            While Not SearchResult Is Nothing
                Dim SelItem As EdmSelItem2 = New EdmSelItem2()
                SelItem.mlID = SearchResult.ID
                SelItem.mlParentID = SearchResult.ParentFolderID
                SelItem.meType = SearchResult.ObjectType
                SelItem.mlVersion = SearchResult.Version
                SearchResult = Search.GetNextResult()
            End While
            inst.SetProgressPos(7, "Task finished searching.")
            Dim NotificationArray(Items.Count - 1) _
              As EdmSelItem2
            Dim ProgresssMsg As String
            If (Items.Count > 0) Then
                ProgresssMsg = "Found " + _
                  Items.Count.ToString() + " files."
                ProgresssMsg = ("No files found.")
            End If
            inst.SetProgressPos(10, ProgresssMsg)
            inst.SetStatus( _
              EdmTaskStatus.EdmTaskStat_DoneOK, 0, "", _
              NotificationArray, ProgresssMsg)
        Catch ex As Runtime.InteropServices.COMException
            inst.SetStatus _
              (EdmTaskStatus.EdmTaskStat_DoneFailed, _
              ex.ErrorCode, "The test task failed!")
        Catch ex As Exception
            inst.SetStatus _
              (EdmTaskStatus.EdmTaskStat_DoneFailed, _
              0, "Non COM test task failure!")
        End Try
    End Sub
    Private Sub OnTaskSetup(ByRef poCmd As EdmCmd, _
      ByRef ppoData As System.Array)
            'Get the property interface used to
            'access the framework
            Dim props As IEdmTaskProperties
            props = poCmd.mpoExtra
            'Set the property flag that says you want a
            'menu item for the user to launch the task
            'and a flag to support scheduling
            props.TaskFlags = _
              EdmTaskFlag.EdmTask_SupportsInitExec + _
            'Set up the menu commands to launch this task
            Dim cmds(0) As EdmTaskMenuCmd
            cmds(0).mbsMenuString = "List Approved files task"
            cmds(0).mbsStatusBarHelp = _
              "This command runs the task add-in to get the" + _
              " names of the files in the Approved state."
            cmds(0).mlCmdID = 1
            cmds(0).mlEdmMenuFlags = _
        Catch ex As Runtime.InteropServices.COMException
            MsgBox("HRESULT = 0x" + _
              ex.ErrorCode.ToString("X") + vbCrLf + _
        Catch ex As Exception
        End Try
    End Sub
    Private Sub PauseToAttachProcess( _
      ByVal callbackType As String)
            'If the debugger isn't already attached to a
            If Not Debugger.IsAttached() Then
                'Launch the debug dialog
                'use a MsgBox dialog to pause execution
                'and allow the user time to attach it
                MsgBox("Attach debugger to process """ + _
                  Process.GetCurrentProcess.ProcessName() + _
                  """ for callback """ + callbackType + _
                  """ before clicking OK.")
            End If
        Catch ex As Exception
        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

Subject:   Feedback on Help Topics
Page:   Create a Task that Finds Approved Files Example (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.