Vb.net Solidworks EPDM API IEdmEnumeratorVariable5::SetVar未按预期工作

Vb.net Solidworks EPDM API IEdmEnumeratorVariable5::SetVar未按预期工作,vb.net,com,solidworks,Vb.net,Com,Solidworks,我正在尝试使用更新一些基于用户输入到windows窗体中的文件卡变量。我的代码执行时,没有错误消息,文件被签出并签回,相应的注释被添加到历史记录中;但是,卡上的变量不会更新 我通过在运行时单步执行代码验证了所有变量都填充了正确的(如预期的)数据。SetVar过程都会顺利进行,但数据卡上的变量不会改变值-即使手动刷新文件夹视图也没有效果 下面是我的代码 这是一个外接程序应用程序,使用VS Community 2015在VB中作为类库项目编写,目标框架为.NET 4.0 努力使这一问题更加简明扼要

我正在尝试使用更新一些基于用户输入到windows窗体中的文件卡变量。我的代码执行时,没有错误消息,文件被签出并签回,相应的注释被添加到历史记录中;但是,卡上的变量不会更新

我通过在运行时单步执行代码验证了所有变量都填充了正确的(如预期的)数据。
SetVar
过程都会顺利进行,但数据卡上的变量不会改变值-即使手动刷新文件夹视图也没有效果


下面是我的代码

这是一个外接程序应用程序,使用VS Community 2015在VB中作为类库项目编写,目标框架为.NET 4.0

努力使这一问题更加简明扼要;在下面,我只包含了执行设置变量的代码片段,然后我还包含了更多代码,以便您可以在需要时了解整个情况


只是提示: 这是执行设置变量工作的代码:

Public Sub OnCmd(ByRef poCmd As EdmCmd,
                 ByRef ppoData As System.Array) Implements IEdmAddIn5.OnCmd

    Dim CommandToRun As MenuCommand

    Try

        With ReceivedCommand
            .SourceVault = poCmd.mpoVault
            .SourceCommand = poCmd
            .SourceSelection = ppoData

            'Get the command structure for the command ID
            Select Case poCmd.meCmdType

                Case EdmCmdType.EdmCmd_Menu
                    CommandToRun = AvailableCommands(.SourceCommand.mlCmdID)

                Case EdmCmdType.EdmCmd_CardButton
                    Select Case True
                        Case poCmd.mbsComment.ToString.ToUpper.Contains("DISPOSITION")
                            DispositionRequest()
                        Case Else : Exit Sub
                    End Select

                Case Else : Exit Sub
            End Select
    '...... (End Try, End Sub, Etc.)
Private Sub DispositionRequest()

    Dim UserDisposition As String

    Using Disposition As New DispositionForm
        With Disposition
            If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub
            Select Case True

                Case .Approve.Checked
                    UserDisposition = "Approved"

                Case .Reject.Checked
                    UserDisposition = "Rejected"

                Case Else : Exit Sub

            End Select
        End With
    End Using



    Dim UserComment As String

    Using Explanation As New DispositionExplanation
        With Explanation

            If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub

            If .ListView1.Items.Count > 0 Then
                 'do some stuff not relevant to this question...
            End If

            UserComment = .Comments.Text

        End With
    End Using

    'This next procedure just gets a list of paths from ReceivedCommand.SourceSelection  - which is just the ppoData argument from the OnCmd procedure - see code block above!
    Dim RequestPaths As List(Of String) = GetSelectedFilePaths()

    For Each Path As String In RequestPaths
        With ReceivedCommand
            Dim RequestFile As IEdmFile5 = .SourceVault.GetFileFromPath(Path)
            Dim ParentFolder As IEdmFolder6 = .SourceVault.GetFolderFromPath(System.IO.Path.GetDirectoryName(Path))
            Dim UnlockLater As Boolean = False

            If Not RequestFile.IsLocked Then
                UnlockLater = True
                RequestFile.LockFile(ParentFolder.ID, .SourceCommand.mlParentWnd, CInt(EdmLockFlag.EdmLock_Simple))
            End If

            Dim CardVariables As IEdmEnumeratorVariable5 = RequestFile.GetEnumeratorVariable

            'We allow users to re-disposition a request so we want to keep any previous disposition information so it is not lost
            Dim CardComment As String = String.Empty
            Dim CardBy As String = String.Empty
            Dim CardDate As String = String.Empty
            Dim CardDisposition As String = String.Empty
            Dim Success As Boolean

            Const CommentVariable As String = "DispComm"
            Const ByVariable As String = "DisposedBy"
            Const DateVariable As String = "DisposedDate"
            Const DispositionVariable As String = "Disposition"

            Success = CardVariables.GetVar(DispositionVariable, "@", CardDisposition)

            If Success Then
                Success = CardVariables.GetVar(CommentVariable, "@", CardComment)
                If Success Then Success = CardVariables.GetVar(ByVariable, "@", CardBy)
                If Success Then Success = CardVariables.GetVar(DateVariable, "@", CardDate)
                If Success Then CardComment = "Previously dispositioned as: """ & CardDisposition & """ by: " & CardBy & " on: " & CardDate & vbNewLine &
                                                 "---------Previous disposition explanation---------" & vbNewLine & CardComment
            End If

            Dim UserManager As IEdmUserMgr5 = .SourceVault
            Dim User As IEdmUser5 = UserManager.GetLoggedInUser

            CardComment = UserComment & CardComment
            CardDate = Today().ToString("yyMMdd", Globalization.CultureInfo.InvariantCulture)
            CardBy = User.Name
            CardDisposition = UserDisposition

            CardVariables.SetVar(DispositionVariable, "@", CardDisposition)
            CardVariables.SetVar(CommentVariable, "@", CardComment)
            CardVariables.SetVar(ByVariable, "@", CardBy)
            CardVariables.SetVar(DateVariable, "@", CardDate)
            CardVariables.Flush()

            If UnlockLater Then RequestFile.UnlockFile(lParentWnd:= .SourceCommand.mlParentWnd,
                                                        bsComment:="Dispositioned as " & CardDisposition,
                                                        lEdmUnlockFlags:=0)
            .SourceVault.RefreshFolder(ParentFolder.LocalPath)
        End With
    Next


End Sub


更广泛的笔划: 类模块级变量:

Private Structure CommandInfo
    Dim SourceVault As IEdmVault11
    Dim SourceCommand As EdmCmd
    Dim SourceSelection As System.Array
    Dim TargetTemplate As System.String
    Dim VerifiedPaths As List(Of String)
End Structure

Private ReceivedCommand As CommandInfo

OnCmd过程(调用方):

Public Sub OnCmd(ByRef poCmd As EdmCmd,
                 ByRef ppoData As System.Array) Implements IEdmAddIn5.OnCmd

    Dim CommandToRun As MenuCommand

    Try

        With ReceivedCommand
            .SourceVault = poCmd.mpoVault
            .SourceCommand = poCmd
            .SourceSelection = ppoData

            'Get the command structure for the command ID
            Select Case poCmd.meCmdType

                Case EdmCmdType.EdmCmd_Menu
                    CommandToRun = AvailableCommands(.SourceCommand.mlCmdID)

                Case EdmCmdType.EdmCmd_CardButton
                    Select Case True
                        Case poCmd.mbsComment.ToString.ToUpper.Contains("DISPOSITION")
                            DispositionRequest()
                        Case Else : Exit Sub
                    End Select

                Case Else : Exit Sub
            End Select
    '...... (End Try, End Sub, Etc.)
Private Sub DispositionRequest()

    Dim UserDisposition As String

    Using Disposition As New DispositionForm
        With Disposition
            If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub
            Select Case True

                Case .Approve.Checked
                    UserDisposition = "Approved"

                Case .Reject.Checked
                    UserDisposition = "Rejected"

                Case Else : Exit Sub

            End Select
        End With
    End Using



    Dim UserComment As String

    Using Explanation As New DispositionExplanation
        With Explanation

            If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub

            If .ListView1.Items.Count > 0 Then
                 'do some stuff not relevant to this question...
            End If

            UserComment = .Comments.Text

        End With
    End Using

    'This next procedure just gets a list of paths from ReceivedCommand.SourceSelection  - which is just the ppoData argument from the OnCmd procedure - see code block above!
    Dim RequestPaths As List(Of String) = GetSelectedFilePaths()

    For Each Path As String In RequestPaths
        With ReceivedCommand
            Dim RequestFile As IEdmFile5 = .SourceVault.GetFileFromPath(Path)
            Dim ParentFolder As IEdmFolder6 = .SourceVault.GetFolderFromPath(System.IO.Path.GetDirectoryName(Path))
            Dim UnlockLater As Boolean = False

            If Not RequestFile.IsLocked Then
                UnlockLater = True
                RequestFile.LockFile(ParentFolder.ID, .SourceCommand.mlParentWnd, CInt(EdmLockFlag.EdmLock_Simple))
            End If

            Dim CardVariables As IEdmEnumeratorVariable5 = RequestFile.GetEnumeratorVariable

            'We allow users to re-disposition a request so we want to keep any previous disposition information so it is not lost
            Dim CardComment As String = String.Empty
            Dim CardBy As String = String.Empty
            Dim CardDate As String = String.Empty
            Dim CardDisposition As String = String.Empty
            Dim Success As Boolean

            Const CommentVariable As String = "DispComm"
            Const ByVariable As String = "DisposedBy"
            Const DateVariable As String = "DisposedDate"
            Const DispositionVariable As String = "Disposition"

            Success = CardVariables.GetVar(DispositionVariable, "@", CardDisposition)

            If Success Then
                Success = CardVariables.GetVar(CommentVariable, "@", CardComment)
                If Success Then Success = CardVariables.GetVar(ByVariable, "@", CardBy)
                If Success Then Success = CardVariables.GetVar(DateVariable, "@", CardDate)
                If Success Then CardComment = "Previously dispositioned as: """ & CardDisposition & """ by: " & CardBy & " on: " & CardDate & vbNewLine &
                                                 "---------Previous disposition explanation---------" & vbNewLine & CardComment
            End If

            Dim UserManager As IEdmUserMgr5 = .SourceVault
            Dim User As IEdmUser5 = UserManager.GetLoggedInUser

            CardComment = UserComment & CardComment
            CardDate = Today().ToString("yyMMdd", Globalization.CultureInfo.InvariantCulture)
            CardBy = User.Name
            CardDisposition = UserDisposition

            CardVariables.SetVar(DispositionVariable, "@", CardDisposition)
            CardVariables.SetVar(CommentVariable, "@", CardComment)
            CardVariables.SetVar(ByVariable, "@", CardBy)
            CardVariables.SetVar(DateVariable, "@", CardDate)
            CardVariables.Flush()

            If UnlockLater Then RequestFile.UnlockFile(lParentWnd:= .SourceCommand.mlParentWnd,
                                                        bsComment:="Dispositioned as " & CardDisposition,
                                                        lEdmUnlockFlags:=0)
            .SourceVault.RefreshFolder(ParentFolder.LocalPath)
        End With
    Next


End Sub

处置请求程序(被调用方):

Public Sub OnCmd(ByRef poCmd As EdmCmd,
                 ByRef ppoData As System.Array) Implements IEdmAddIn5.OnCmd

    Dim CommandToRun As MenuCommand

    Try

        With ReceivedCommand
            .SourceVault = poCmd.mpoVault
            .SourceCommand = poCmd
            .SourceSelection = ppoData

            'Get the command structure for the command ID
            Select Case poCmd.meCmdType

                Case EdmCmdType.EdmCmd_Menu
                    CommandToRun = AvailableCommands(.SourceCommand.mlCmdID)

                Case EdmCmdType.EdmCmd_CardButton
                    Select Case True
                        Case poCmd.mbsComment.ToString.ToUpper.Contains("DISPOSITION")
                            DispositionRequest()
                        Case Else : Exit Sub
                    End Select

                Case Else : Exit Sub
            End Select
    '...... (End Try, End Sub, Etc.)
Private Sub DispositionRequest()

    Dim UserDisposition As String

    Using Disposition As New DispositionForm
        With Disposition
            If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub
            Select Case True

                Case .Approve.Checked
                    UserDisposition = "Approved"

                Case .Reject.Checked
                    UserDisposition = "Rejected"

                Case Else : Exit Sub

            End Select
        End With
    End Using



    Dim UserComment As String

    Using Explanation As New DispositionExplanation
        With Explanation

            If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub

            If .ListView1.Items.Count > 0 Then
                 'do some stuff not relevant to this question...
            End If

            UserComment = .Comments.Text

        End With
    End Using

    'This next procedure just gets a list of paths from ReceivedCommand.SourceSelection  - which is just the ppoData argument from the OnCmd procedure - see code block above!
    Dim RequestPaths As List(Of String) = GetSelectedFilePaths()

    For Each Path As String In RequestPaths
        With ReceivedCommand
            Dim RequestFile As IEdmFile5 = .SourceVault.GetFileFromPath(Path)
            Dim ParentFolder As IEdmFolder6 = .SourceVault.GetFolderFromPath(System.IO.Path.GetDirectoryName(Path))
            Dim UnlockLater As Boolean = False

            If Not RequestFile.IsLocked Then
                UnlockLater = True
                RequestFile.LockFile(ParentFolder.ID, .SourceCommand.mlParentWnd, CInt(EdmLockFlag.EdmLock_Simple))
            End If

            Dim CardVariables As IEdmEnumeratorVariable5 = RequestFile.GetEnumeratorVariable

            'We allow users to re-disposition a request so we want to keep any previous disposition information so it is not lost
            Dim CardComment As String = String.Empty
            Dim CardBy As String = String.Empty
            Dim CardDate As String = String.Empty
            Dim CardDisposition As String = String.Empty
            Dim Success As Boolean

            Const CommentVariable As String = "DispComm"
            Const ByVariable As String = "DisposedBy"
            Const DateVariable As String = "DisposedDate"
            Const DispositionVariable As String = "Disposition"

            Success = CardVariables.GetVar(DispositionVariable, "@", CardDisposition)

            If Success Then
                Success = CardVariables.GetVar(CommentVariable, "@", CardComment)
                If Success Then Success = CardVariables.GetVar(ByVariable, "@", CardBy)
                If Success Then Success = CardVariables.GetVar(DateVariable, "@", CardDate)
                If Success Then CardComment = "Previously dispositioned as: """ & CardDisposition & """ by: " & CardBy & " on: " & CardDate & vbNewLine &
                                                 "---------Previous disposition explanation---------" & vbNewLine & CardComment
            End If

            Dim UserManager As IEdmUserMgr5 = .SourceVault
            Dim User As IEdmUser5 = UserManager.GetLoggedInUser

            CardComment = UserComment & CardComment
            CardDate = Today().ToString("yyMMdd", Globalization.CultureInfo.InvariantCulture)
            CardBy = User.Name
            CardDisposition = UserDisposition

            CardVariables.SetVar(DispositionVariable, "@", CardDisposition)
            CardVariables.SetVar(CommentVariable, "@", CardComment)
            CardVariables.SetVar(ByVariable, "@", CardBy)
            CardVariables.SetVar(DateVariable, "@", CardDate)
            CardVariables.Flush()

            If UnlockLater Then RequestFile.UnlockFile(lParentWnd:= .SourceCommand.mlParentWnd,
                                                        bsComment:="Dispositioned as " & CardDisposition,
                                                        lEdmUnlockFlags:=0)
            .SourceVault.RefreshFolder(ParentFolder.LocalPath)
        End With
    Next


End Sub
发件人:

bsCfgName:存储变量值的配置或布局的名称不支持配置的文件夹和文件类型的空字符串

我使用的是一个不支持配置的虚拟文件。 我看到一个C示例处理一个虚拟文件,它们传递空引用,所以我重新阅读了文档并看到了上面的摘录,所以我将mboconfiguration参数的代码从
“@”
更改为
String.Empty
,现在它开始工作了

CardVariables.SetVar(DispositionVariable, String.Empty, CardDisposition)
CardVariables.SetVar(CommentVariable, String.Empty, CardComment)
CardVariables.SetVar(ByVariable, String.Empty, CardBy)
CardVariables.SetVar(DateVariable, String.Empty, CardDate)
CardVariables.Flush()

我读了那本精美的印刷品。。。不要刷新,在10版本的枚举器上使用CloseFile(true)。