AnsweredAssumed Answered

SetVar returns "File is not checked out by you" when it is

Question asked by Tara Campese on Aug 25, 2016
Latest reply on Aug 29, 2016 by Michael Dekoning

I am writing an add-in to prompt users to fill out a revision description when an approved drawing has been revised. I used to have Dispatch do this, but there were too many glitches with Dispatch to make it useful. I am able to use GetVar just fine, but when I use SetVar I get "The file isn't checked out by you, which is required by the operation". But when the program terminates, the file IS checked out by me on my workstation (which is done with the .lockfile command prior to setting the variable).

 

I am using VB.net with Solidworks and epdm 2016 SP4

 

Here is the code for reference:

Imports System.Windows.Forms
Imports EdmLib

Public Class MainRevTable
    Implements IEdmAddIn5

    Public Sub GetAddInInfo(ByRef poInfo As EdmAddInInfo, ByVal poVault As IEdmVault5, ByVal poCmdMgr As IEdmCmdMgr5) Implements IEdmAddIn5.GetAddInInfo

        Try
            ' Specify add-in information
            poInfo.mbsAddInName = "Revision Table Prompt"
            poInfo.mbsCompany = "RadiaBeam Technologies"
            poInfo.mbsDescription = "Prompts user to input revision data for drawings during specified state changes."
            poInfo.mlAddInVersion = 1

            ' Specify minimum version of SolidWorks Enterprise PDM
            poInfo.mlRequiredVersionMajor = 6
            poInfo.mlRequiredVersionMinor = 4

            '' Register a menu command
            'poCmdMgr.AddCmd(1, "Test Rev Table", EdmMenuFlags.EdmMenu_Nothing)

            'Add Hooks
            poCmdMgr.AddHook(EdmCmdType.EdmCmd_PreState)

        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 EdmCmd, ByRef ppoData As System.Array) Implements IEdmAddIn5.OnCmd

        Try

            'Attach to vault 
            Dim vault As IEdmVault5 = poCmd.mpoVault
            Dim AffectedFile As EdmCmdData

            Select Case poCmd.meCmdType
                'A file has changed state
                Case EdmCmdType.EdmCmd_PreState
                    For Each AffectedFile In ppoData
                        If AffectedFile.mbsStrData2 = "Engineering Check" And Right(AffectedFile.mbsStrData1, 6) = "slddrw" Then
                            Dim DRWFile As IEdmFile5 = vault.GetObject(EdmObjectType.EdmObject_File, AffectedFile.mlObjectID1)
                            Dim vars As IEdmEnumeratorVariable8 = DRWFile.GetEnumeratorVariable
                            'Dim vars As IEdmEnumeratorVariable5 = poCmd.mpoExtra
                            Dim RevDesc01 As String = ""
                            'vars = DRWFile.GetEnumeratorVariable
                            DrwName = ""
                            NewDescription = ""

                            DRWFile.LockFile(AffectedFile.mlObjectID2, poCmd.mlParentWnd)

                            vars.GetVar("RevDesc01", "@", RevDesc01)

                            If RevDesc01 = "" Then
                                NewDescription = "Initial Release"
                            Else
                                DrwName = DRWFile.Name
                                DrwName = Left(DrwName, Len(DrwName) - 7)
                                uRevDesc = New RevDesc
                                vars.GetVar("TempRevDesc", "@", uRevDesc.TextBox.Text)
                                NewDescription = "Hello"
                                'uRevDesc.DrawingLabel.Text = "Enter a Revision Description for " & DrwName & ":"
                                'uRevDesc.ShowDialog()
                            End If

                            vars.SetVar("TempRevDesc", "@", NewDescription)
                            vars.Flush()
                            DRWFile.UnlockFile(0, "Set TempRevDesc as " & NewDescription)
                        End If

                    Next affectedfile

                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

 

 

With Global Variables:

 

Imports EdmLib

Public Module GlobalVars

    Public DrwName As String
    Public uRevDesc As RevDesc
    Public NewDescription As String

End Module

Attachments

Outcomes