39 Replies Latest reply on Feb 14, 2018 12:13 PM by Jacob Corder

    EPDM Prestate Transition File Check and Variable Update

    Adon Nicholls

      Hi All,

      I am currently making a automated check for when we up-rev parts etc. through the system.

      I have attempted a Pre-state hook but I can't get it to work. What i should do is when a transition is done it runs a case - '1080' which equates to the 'ChangeNoteChecker' class. This is followed by a  load of generated functions it seemed to create after I put the hook which I havn't touched.

      In the 'ChangeNoteChecker' class it should check for a location of files. In my code below it is a pdf file. When it verifies that one is there it should check out the data card file. update a checkbox variable and check it and then check the file back in and proceed with the transition.

      As it is it doesn't even check the file out or give an error so I don't know what is going on.

      I get one error if I leave the first message box un-commented out on the Pre-state Hook class under the add hook line which says it does not fall within expected range?

      Also MRP Checker has no real code id just open and close class for the moment.

        • Re: EPDM Prestate Transition File Check and Variable Update
          Lee CS Young

          There's no id when creating hooks. Id's are for menu commands so you know what command was called.

           

          Hooks should be; poCmdMgr.AddHook(EdmCmdType.EdmCmd_PreState).

            • Re: EPDM Prestate Transition File Check and Variable Update
              Adon Nicholls

              Hi Guys,

              I tried it out and now I get this error when I run the transition. Any clues?

              Thanks for the help so far.

                • Re: EPDM Prestate Transition File Check and Variable Update
                  Jacob Corder

                  take a screenshot of your references in the project properties please. 

                   

                  your no interface error i have seen before i need to know the references and how your project is setup.

                  • Re: EPDM Prestate Transition File Check and Variable Update
                    Jacob Corder

                     

                    check your registry, do you have this key?

                    Computer\HKEY_CLASSES_ROOT\Interface\{AAFEA179-C9AE-4032-81C4-2AFCAA67B81A}\TypeLib

                        • Re: EPDM Prestate Transition File Check and Variable Update
                          Jacob Corder

                          ok. i got it..

                           

                          MPOExtra is a IEDMCMDNode on PreTransition

                          2018 SOLIDWORKS API Help - EdmCmdData Structure

                           

                           

                          you will have to get the ConfigList from the file

                          2018 SOLIDWORKS API Help - GetConfigurations Method (IEdmFile5)

                          • Re: EPDM Prestate Transition File Check and Variable Update
                            Jacob Corder

                            change it here.  the EDMCMDData structure changes with every dang callback..  i find it annoying personally. but it is what it is.

                                • Re: EPDM Prestate Transition File Check and Variable Update
                                  Adon Nicholls

                                  I still get the same error unfortunately.

                                    • Re: EPDM Prestate Transition File Check and Variable Update
                                      Adon Nicholls

                                      I also tried this but it still gave the same error.

                                        • Re: EPDM Prestate Transition File Check and Variable Update
                                          Adon Nicholls

                                          Is it because I need to change stuff in this aswell?

                                            • Re: EPDM Prestate Transition File Check and Variable Update
                                              Jacob Corder

                                              No you didn't remove the part that is erroring out.

                                               

                                              You need to have safer code.  When dealing with objects that have unknown types, you need to use methods like TRYCAST OR typeof 

                                              DIM CONFIGS AS IEDMSTRLIST5= NOTHING

                                              IF TYPEOF MPOEXTRA IS IEDMSTRLIST5 THEN

                                                    CONFIGLIST = MPOEXTRA

                                              ELSE

                                                    CONFIGLIST = VFILE.GETCONFIGURATIONS

                                              END IF

                                                • Re: EPDM Prestate Transition File Check and Variable Update
                                                  Adon Nicholls

                                                  Hi Jacob,

                                                   

                                                  I tried doing this but it gave the error once more my code looks like:

                                                   

                                                  Try

                                                              '''''

                                                              Dim vfileEnumvars As IEdmEnumeratorVariable5 = poCmd.mpoExtra

                                                              Dim Config As String

                                                              Dim cfgList As EdmStrLst5 = Nothing

                                                              cfgList = vFile.GetConfigurations

                                                              If TypeOf mpoextra Is IEdmStrLst5 Then

                                                                  cfgList = mpoExtra

                                                              Else

                                                                  Config = vFile.GetConfigurations

                                                              End If

                                                   

                                                  Followed by all the bits that check out the file, change the variable and then check it back in and then this as a function at the end.

                                                   

                                                     Private Function IsConfigInList(ByVal cfglist As IEdmStrLst5, ByVal ConfigName As String) As Boolean

                                                          IsConfigInList = False

                                                          Try

                                                              Dim CurConfig As String

                                                              Dim Pos As IEdmPos5 = cfglist.GetHeadPosition()

                                                              While Not Pos.IsNull

                                                                  CurConfig = cfglist.GetNext(Pos)

                                                                  If CurConfig = ConfigName Then

                                                                      IsConfigInList = True

                                                                      Exit While

                                                                  End If

                                                              End While

                                                              Return IsConfigInList

                                                          Catch ex As Runtime.InteropServices.COMException

                                                              MsgBox("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)

                                                          Catch ex As Exception

                                                              MsgBox(ex.Message)

                                                          End Try

                                                      End Function

                                                  End Class

                                                  • Re: EPDM Prestate Transition File Check and Variable Update
                                                    Adon Nicholls

                                                    I've changed Config to cfglist in the else and in the set var

                                                    • Re: EPDM Prestate Transition File Check and Variable Update
                                                      Adon Nicholls

                                                      It doesn't throw an error anymore but doesn't do anything else when the transition happens not even check out the file.  I've commented out the unlock file and the set variable to find the problem.

                                                        • Re: EPDM Prestate Transition File Check and Variable Update
                                                          Jacob Corder

                                                          your code is still wrong.

                                                           

                                                          do this

                                                          Private Function VerifyEPDMConfigExists(ByVal VFile As IEdmFile8, ByVal poCmd As EdmCmdData, ByVal ConfigName As String) As Boolean

                                                                  Dim cfgList As IEdmStrLst5 = Nothing

                                                                  Try

                                                                      If TypeOf poCmd.mpoExtra Is IEdmStrLst5 Then

                                                                          cfgList = poCmd.mpoExtra

                                                                      Else

                                                                          cfgList = VFile.GetConfigurations

                                                                      End If

                                                                  Catch ex As Exception

                                                                  End Try

                                                                  Return IsConfigInList(cfgList, ConfigName)

                                                              End Function

                                                              Private Function IsConfigInList(ByVal cfglist As IEdmStrLst5, ByVal ConfigName As String) As Boolean

                                                                  If cfglist Is Nothing Then Return False

                                                                  If Len(Trim(ConfigName)) = 0 Then Return False

                                                                  Try

                                                                      Dim CurConfig As String

                                                                      Dim Pos As IEdmPos5 = cfglist.GetHeadPosition()

                                                                      While Not Pos.IsNull

                                                                          CurConfig = cfglist.GetNext(Pos)

                                                                          If CurConfig = ConfigName Then

                                                                              Return True

                                                                          End If

                                                                      End While

                                                                  Catch ex As Runtime.InteropServices.COMException

                                                                      MsgBox("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)

                                                                  Catch ex As Exception

                                                                      MsgBox(ex.Message)

                                                                  End Try

                                                                  Return False

                                                              End Function

                                                            • Re: EPDM Prestate Transition File Check and Variable Update
                                                              Jacob Corder

                                                              so i dont know if you can check out a file in PreStateChange.

                                                               

                                                              i think you need to cancel the state change. 

                                                               

                                                              certain things can and cant be done during certain hook types

                                                               

                                                              2018 SOLIDWORKS API Help - mbCancel Field

                                                               

                                                              So the file being transitioned cannot be checked out. Someone else may verify that this is true or false but i dont think you can.

                                                               

                                                              you can however check out files that are NOT in the list of files that are trying to be state changed.

                                                               

                                                              i am not 100% sure of this by the way but i do know you cant do whatever you want at any state change.

                                                               

                                                              if you need to cancel the transition, then launch a form that allows the user to click a button that continues the operation.

                                                               

                                                              setting cancel cancels the transition of ALL files that are trying to be transitioned.. dumb i know but it is what it is.

                                                            • Re: EPDM Prestate Transition File Check and Variable Update
                                                              Jacob Corder

                                                              you might be able to execute this code on POST state change.  try that

                                                                • Re: EPDM Prestate Transition File Check and Variable Update
                                                                  Adon Nicholls

                                                                  Thanks for all the help, I know it must be quite frustrating.

                                                                  I have changed the hook to a post state hook

                                                                   

                                                                  This is the code I have now of the change checker class. At the moment it throws no error but also does not seem to run the processes e.g. check out file, write variable and then check in the file.

                                                                   

                                                                  Imports EdmLib

                                                                  Imports System.Windows.Forms

                                                                  Imports System.IO

                                                                  Imports Microsoft.Office.Interop

                                                                  Imports Microsoft.Office.Interop.Word

                                                                  Imports System

                                                                  Imports System.Drawing

                                                                  Imports System.Data

                                                                  Imports System.Collections.Generic

                                                                  Imports Microsoft.VisualBasic

                                                                   

                                                                  Public Class ChangeNoteChecker

                                                                   

                                                                      Public AffectedFile As EdmCmdData

                                                                      Public mpoExtra As System.Object

                                                                      Dim v As IEdmVault5

                                                                      Dim vfileID As Integer

                                                                      Dim vFile As IEdmFile5

                                                                      Dim vfileEnumvars As IEdmEnumeratorVariable5

                                                                      Dim vFolder As IEdmFolder5

                                                                   

                                                                      Private Function VerifyEPDMConfigExists(ByVal VFile As IEdmFile8, ByVal poCmd As EdmCmdData, ByVal ConfigName As String) As Boolean

                                                                          Dim cfgList As IEdmStrLst5 = Nothing

                                                                          Try

                                                                              If TypeOf poCmd.mpoExtra Is IEdmStrLst5 Then

                                                                                  cfgList = poCmd.mpoExtra

                                                                              Else

                                                                                  cfgList = VFile.GetConfigurations

                                                                              End If

                                                                          Catch ex As Exception

                                                                          End Try

                                                                          Return IsConfigInList(cfgList, ConfigName)

                                                                      End Function

                                                                   

                                                                   

                                                                      Friend Sub New(ByRef poCmd As EdmLib.EdmCmd, ByRef ppoData As System.Array)

                                                                   

                                                                          v = poCmd.mpoVault

                                                                          vfileID = ppoData(0).mlobjectId1

                                                                          vFile = v.GetObject(EdmObjectType.EdmObject_File, vfileID)

                                                                          vfileEnumvars = vFile.GetEnumeratorVariable

                                                                          vFolder = v.GetFolderFromPath(v.RootFolderPath & "\Engineering\Design\Change Managements 2")

                                                                   

                                                                          ''''''' Card Variables Used'''''''

                                                                          Dim EC0Number As String = ""

                                                                          Dim PartNumber As String = ""

                                                                          Dim Revision As String = ""

                                                                          Dim ChangenoteRev As Integer            ''''''''' epdm checkbox'''''''''''''

                                                                          Dim ChangenotePDF As Integer

                                                                          Dim ChangenoteDevRelease As Integer

                                                                          Dim ChangenoteDXF As Integer

                                                                          Dim WIP As String = ""

                                                                          Dim STOCK As String = ""

                                                                          Dim FIELD As String = ""

                                                                          Dim FileNamePDF As String = PartNumber & "-" & Revision & ".pdf"

                                                                          Dim FileNameEC As String = EC0Number & ".CN2.cvd"

                                                                   

                                                                          vfileEnumvars.GetVar("Number", "", EC0Number)

                                                                          vfileEnumvars.GetVar("Part Number", "", PartNumber)

                                                                          vfileEnumvars.GetVar("Revision", "", Revision)

                                                                          vfileEnumvars.GetVar("CN_Rev", "", ChangenoteRev)

                                                                          vfileEnumvars.GetVar("CN_DevRelease", "", ChangenoteDevRelease)

                                                                          vfileEnumvars.GetVar("CN_PDF", "", ChangenotePDF)

                                                                          vfileEnumvars.GetVar("CN_DXF", "", ChangenoteDXF)

                                                                          vfileEnumvars.GetVar("CN_WIP", "", WIP)

                                                                          vfileEnumvars.GetVar("CN_STOCK", "", STOCK)

                                                                          vfileEnumvars.GetVar("CN_FIELD", "", FIELD)

                                                                   

                                                                          ''''''Find PDFs'''''''''''''

                                                                          Try

                                                                              'Dim vfileEnumvars As IEdmEnumeratorVariable5 = poCmd.mpoExtra

                                                                              If AffectedFile.mbsStrData2 = "Change Note Design Approval" Then

                                                                   

                                                                                  vFile.closefile(False)

                                                                                  Dim FileDirectory As String() = Directory.GetFiles("\\Network\GILO-TS-1\123 Folders\Drawings\")

                                                                                  For Each FoundFile In FileDirectory

                                                                                      'If (System.IO.File.Exists("\\Network\GILO-TS-1\123 Folders\Drawings\" & FileNamePDF)) Then

                                                                                      If (System.IO.File.Exists("C:\Rotron_Vault_Test2\Engineering\Design\Change Managements 2" & FileNamePDF)) Then

                                                                                          ChangenotePDF = 1

                                                                   

                                                                                          v = poCmd.mpoVault

                                                                                          vfileID = ppoData(0).mlobjectId1

                                                                                          vFile = v.GetFileFromPath("C:\Rotron_Vault_Test2\Engineering\Design\Change Managements 2" & FileNameEC)

                                                                                          Dim pos As IEdmPos5

                                                                                          pos = vFolder.GetFirstFilePosition

                                                                   

                                                                                          If Not vFile.IsLocked Then

                                                                                              Try

                                                                                                  vFile.LockFile(vFolder.ID, "", CInt(EdmLockFlag.EdmLock_Simple))

                                                                                              Catch ex As Exception

                                                                                                  MsgBox(ex.Message)

                                                                                              End Try

                                                                                          End If

                                                                   

                                                                                          vfileEnumvars = vFile.GetEnumeratorVariable

                                                                                          vfileEnumvars.SetVar("CN_PDF", "", 1)

                                                                                          vFile.CloseFile(True)

                                                                   

                                                                                          vFile.UnlockFile(vFolder.ID, "", CInt(EdmLockFlag.EdmLock_Simple))

                                                                                      End If

                                                                                  Next

                                                                              End If

                                                                          Catch ex As Exception

                                                                              MessageBox.Show(ex.Message)

                                                                          End Try

                                                                      End Sub

                                                                   

                                                                   

                                                                      Private Function IsConfigInList(ByVal cfglist As IEdmStrLst5, ByVal ConfigName As String) As Boolean

                                                                          If cfglist Is Nothing Then Return False

                                                                          If Len(Trim(ConfigName)) = 0 Then Return False

                                                                          Try

                                                                              Dim CurConfig As String

                                                                              Dim Pos As IEdmPos5 = cfglist.GetHeadPosition()

                                                                              While Not Pos.IsNull

                                                                                  CurConfig = cfglist.GetNext(Pos)

                                                                                  If CurConfig = ConfigName Then

                                                                                      Return True

                                                                                  End If

                                                                              End While

                                                                          Catch ex As Runtime.InteropServices.COMException

                                                                              MsgBox("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)

                                                                          Catch ex As Exception

                                                                              MsgBox(ex.Message)

                                                                          End Try

                                                                          Return False

                                                                      End Function

                                                                  End Class

                                                                    • Re: EPDM Prestate Transition File Check and Variable Update
                                                                      Jacob Corder

                                                                      still wrong.

                                                                       

                                                                      you  have to use the intelisense.

                                                                      you cannot call VFile.CloseFile(false)  VFile is IEDMFile8

                                                                      you mean VFileEnumVars.CloseFile(False)

                                                                       

                                                                      Verify the method exists before you just use it. 

                                                                      • Re: EPDM Prestate Transition File Check and Variable Update
                                                                        Jacob Corder

                                                                        turn Option Strict on so you can see what is going on.

                                                                         

                                                                        you should not use an integer in a byref call

                                                                         

                                                                                Dim EC0Number As String = ""

                                                                                Dim PartNumber As String = ""

                                                                                Dim Revision As String = ""

                                                                                Dim ChangenoteRev As STRING''''''''' epdm checkbox'''''''''''''

                                                                                Dim ChangenotePDF As STRING

                                                                                Dim ChangenoteDevRelease As STRING

                                                                                Dim ChangenoteDXF As STRING

                                                                                Dim WIP As String = ""

                                                                                Dim STOCK As String = ""

                                                                                Dim FIELD As String = ""

                                                                                Dim FileNamePDF As String = PartNumber & "-" & Revision & ".pdf"

                                                                                Dim FileNameEC As String = EC0Number & ".CN2.cvd"

                                                                         

                                                                         

                                                                                vfileEnumvars.GetVar("Number", "", EC0Number)

                                                                                vfileEnumvars.GetVar("Part Number", "", PartNumber)

                                                                                vfileEnumvars.GetVar("Revision", "", Revision)

                                                                                vfileEnumvars.GetVar("CN_Rev", "", ChangenoteRev)

                                                                                vfileEnumvars.GetVar("CN_DevRelease", "", ChangenoteDevRelease)

                                                                                vfileEnumvars.GetVar("CN_PDF", "", ChangenotePDF)

                                                                                vfileEnumvars.GetVar("CN_DXF", "", ChangenoteDXF)

                                                                                vfileEnumvars.GetVar("CN_WIP", "", WIP)

                                                                                vfileEnumvars.GetVar("CN_STOCK", "", STOCK)

                                                                                vfileEnumvars.GetVar("CN_FIELD", "", FIELD)

                                                                         

                                                                         

                                                                        Change top Declaration

                                                                            Dim vfileEnumvars As IEdmEnumeratorVariable5

                                                                        to

                                                                            Dim vfileEnumvars As IEdmEnumeratorVariable8

                                                                         

                                                                        change

                                                                          Dim vFile As IEdmFile5

                                                                        to the latest one you can like

                                                                          Dim vFile As IEdmFile10

                                                                         

                                                                         

                                                                        there is a lot wrong here bud.  its not working because your code is setting the fileNamePDF to part number and rev but they havent been set to anything yet.

                                                                         

                                                                         

                                                                         

                                                                        try this code out

                                                                         

                                                                         

                                                                        Public AffectedFile As EdmCmdData

                                                                            Public mpoExtra As System.Object

                                                                            Dim v As IEdmVault5

                                                                            Dim vfileID As Integer

                                                                            Dim vFile As IEdmFile10

                                                                         

                                                                         

                                                                         

                                                                         

                                                                            Dim vFolder As IEdmFolder8

                                                                         

                                                                         

                                                                            Private Function VerifyEPDMConfigExists(ByVal VFile As IEdmFile8, ByVal poCmd As EdmCmdData, ByVal ConfigName As String) As Boolean

                                                                                Dim cfgList As IEdmStrLst5 = Nothing

                                                                                Try

                                                                                    If TypeOf poCmd.mpoExtra Is IEdmStrLst5 Then

                                                                                        cfgList = poCmd.mpoExtra

                                                                                    Else

                                                                                        cfgList = VFile.GetConfigurations

                                                                                    End If

                                                                                Catch ex As Exception

                                                                                End Try

                                                                                Return IsConfigInList(cfgList, ConfigName)

                                                                            End Function

                                                                         

                                                                         

                                                                         

                                                                         

                                                                            Friend Sub New(ByRef poCmd As EdmLib.EdmCmd, ByRef ppoData As System.Array)

                                                                                If ppoData Is Nothing Then Exit Sub

                                                                                If TypeOf ppoData(0) Is EdmCmdData Then

                                                                                    AffectedFile = ppoData(0)

                                                                                Else

                                                                                    Exit Sub

                                                                                End If

                                                                         

                                                                         

                                                                                If AffectedFile.mbsStrData2 = "Change Note Design Approval" Then

                                                                                    v = poCmd.mpoVault

                                                                         

                                                                         

                                                                                    vfileID = ppoData(0).mlobjectId1

                                                                                    vFile = v.GetObject(EdmObjectType.EdmObject_File, vfileID)

                                                                         

                                                                         

                                                                                    vFolder = v.GetFolderFromPath(v.RootFolderPath & "\Engineering\Design\Change Managements 2")

                                                                         

                                                                         

                                                                                    ''''''' Card Variables Used'''''''

                                                                                    Dim EC0Number As String = ""

                                                                                    Dim PartNumber As String = ""

                                                                                    Dim Revision As String = ""

                                                                                    Dim ChangenoteRev As String = ""      ''''''''' epdm checkbox'''''''''''''

                                                                                    Dim ChangenotePDF As String = ""

                                                                                    Dim ChangenoteDevRelease As String = ""

                                                                                    Dim ChangenoteDXF As String = ""

                                                                                    Dim WIP As String = ""

                                                                                    Dim STOCK As String = ""

                                                                                    Dim FIELD As String = ""

                                                                         

                                                                         

                                                                                    Dim vfileEnumvars As IEdmEnumeratorVariable8 = vFile.GetEnumeratorVariable

                                                                                    If Not vfileEnumvars Is Nothing Then

                                                                                        Try

                                                                                            vfileEnumvars.GetVar("Number", "", EC0Number)

                                                                                            vfileEnumvars.GetVar("Part Number", "", PartNumber)

                                                                                            vfileEnumvars.GetVar("Revision", "", Revision)

                                                                                            vfileEnumvars.GetVar("CN_Rev", "", ChangenoteRev)

                                                                                            vfileEnumvars.GetVar("CN_DevRelease", "", ChangenoteDevRelease)

                                                                                            vfileEnumvars.GetVar("CN_PDF", "", ChangenotePDF)

                                                                                            vfileEnumvars.GetVar("CN_DXF", "", ChangenoteDXF)

                                                                                            vfileEnumvars.GetVar("CN_WIP", "", WIP)

                                                                                            vfileEnumvars.GetVar("CN_STOCK", "", STOCK)

                                                                                            vfileEnumvars.GetVar("CN_FIELD", "", FIELD)

                                                                                        Catch ex As Exception

                                                                                        Finally

                                                                                            vfileEnumvars.CloseFile(False)

                                                                                            vfileEnumvars = Nothing

                                                                                        End Try

                                                                                    End If

                                                                                    Dim FileNamePDF As String = PartNumber & "-" & Revision & ".pdf"

                                                                                    Dim FileNameEC As String = EC0Number & ".CN2.cvd"

                                                                                    ''''''Find PDFs'''''''''''''

                                                                                    Try

                                                                                        'Dim vfileEnumvars As IEdmEnumeratorVariable5 = poCmd.mpoExtra

                                                                         

                                                                         

                                                                         

                                                                         

                                                                                        'If (System.IO.File.Exists("\\Network\GILO-TS-1\123 Folders\Drawings\" & FileNamePDF)) Then

                                                                                        'BE CAREFUL USING SYSTEM.IO.FILE.EXISTS as if the file doesnt exist on the local computer, it will return false even if it is in EPDM

                                                                         

                                                                         

                                                                                        'If (System.IO.File.Exists("C:\Rotron_Vault_Test2\Engineering\Design\Change Managements 2\" & FileNamePDF)) Then

                                                                                        ChangenotePDF = 1

                                                                                        vFile = v.GetFileFromPath("C:\Rotron_Vault_Test2\Engineering\Design\Change Managements 2\" & FileNameEC)

                                                                                        'V FILE IS NOW ECO NUMBER.CN2.CVD CORRECT. THIS IS THE FILE YOU WANT TO CHECK OUT?

                                                                                        If Not vFile Is Nothing Then

                                                                                            Dim pos As IEdmPos5

                                                                                            pos = vFolder.GetFirstFilePosition

                                                                         

                                                                         

                                                                                            If Not vFile.IsLocked Then

                                                                                                Try

                                                                                                    vFile.LockFile(vFolder.ID, "", CInt(EdmLockFlag.EdmLock_Simple))

                                                                                                Catch ex As Exception

                                                                                                    MsgBox(ex.Message)

                                                                                                End Try

                                                                                            End If

                                                                                            vfileEnumvars = vFile.GetEnumeratorVariable

                                                                                            vfileEnumvars.SetVar("CN_PDF", "", 1)

                                                                                            vfileEnumvars.CloseFile(True)

                                                                         

                                                                         

                                                                                            vFile.UnlockFile(vFolder.ID, "", CInt(EdmLockFlag.EdmLock_Simple))

                                                                                        End If

                                                                                        'End If

                                                                         

                                                                         

                                                                         

                                                                         

                                                                                    Catch ex As Exception

                                                                                        MessageBox.Show(ex.Message)

                                                                                    End Try

                                                                                End If

                                                                            End Sub

                                                                         

                                                                         

                                                                         

                                                                         

                                                                            Private Function IsConfigInList(ByVal cfglist As IEdmStrLst5, ByVal ConfigName As String) As Boolean

                                                                                If cfglist Is Nothing Then Return False

                                                                                If Len(Trim(ConfigName)) = 0 Then Return False

                                                                                Try

                                                                                    Dim CurConfig As String

                                                                                    Dim Pos As IEdmPos5 = cfglist.GetHeadPosition()

                                                                                    While Not Pos.IsNull

                                                                                        CurConfig = cfglist.GetNext(Pos)

                                                                                        If CurConfig = ConfigName Then

                                                                                            Return True

                                                                                        End If

                                                                                    End While

                                                                                Catch ex As Runtime.InteropServices.COMException

                                                                                    MsgBox("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)

                                                                                Catch ex As Exception

                                                                                    MsgBox(ex.Message)

                                                                                End Try

                                                                                Return False

                                                                            End Function

                                                                          • Re: EPDM Prestate Transition File Check and Variable Update
                                                                            Jacob Corder

                                                                                      'If (System.IO.File.Exists("C:\Rotron_Vault_Test2\Engineering\Design\Change Managements 2\" & FileNamePDF)) Then

                                                                                            ChangenotePDF = 1

                                                                                            vFile = v.GetFileFromPath("C:\Rotron_Vault_Test2\Engineering\Design\Change Managements 2\" & FileNameEC)

                                                                             

                                                                            you were checking if a PDF exists then getting the FileNameEC file from the vault.

                                                                            but it was "Change Managements 2 " & FilenameEC" as the actual file name.   If that is correct remove the RED \ above

                                                                              • Re: EPDM Prestate Transition File Check and Variable Update
                                                                                Adon Nicholls

                                                                                Thank you for noticing the errors

                                                                                I've changed them and then am tring to run it as a poststate and just check the file out although still with no luck

                                                                                heres what i have now:

                                                                                 

                                                                                Public Class ChangeNoteChecker

                                                                                 

                                                                                    Public AffectedFile As EdmCmdData

                                                                                    Public mpoExtra As System.Object

                                                                                    Dim v As IEdmVault5

                                                                                    Dim vfileID As Integer

                                                                                    Dim vFile As IEdmFile5

                                                                                    Public vfileEnumvars As IEdmEnumeratorVariable8

                                                                                    Dim vFolder As IEdmFolder5

                                                                                 

                                                                                    Friend Sub New(ByRef poCmd As EdmLib.EdmCmd, ByRef ppoData As System.Array)

                                                                                     

                                                                                  v = poCmd.mpoVault

                                                                                        vfileID = ppoData(0).mlobjectId1

                                                                                        vFile = v.GetObject(EdmObjectType.EdmObject_File, vfileID)

                                                                                        vfileEnumvars = vFile.GetEnumeratorVariable

                                                                                        vFolder = v.GetFolderFromPath(v.RootFolderPath & "\Engineering\Design\Change Managements 2")

                                                                                 

                                                                                        ''''''' Card Variables Used'''''''

                                                                                        Dim EC0Number As String = ""

                                                                                        Dim PartNumber As String = ""

                                                                                        Dim Revision As String = ""

                                                                                        Dim ChangenoteRev As String = ""   '      ''''''''' epdm checkbox'''''''''''''

                                                                                        Dim ChangenotePDF As String = ""

                                                                                        Dim ChangenoteDevRelease As String = "" '

                                                                                        Dim ChangenoteDXF As String = "" '

                                                                                        Dim WIP As String = ""

                                                                                        Dim STOCK As String = ""

                                                                                        Dim FIELD As String = ""

                                                                                        Dim FileNamePDF As String = PartNumber & "-" & Revision & ".pdf"

                                                                                        Dim FileNameEC As String = EC0Number & ".CN2.cvd"

                                                                                 

                                                                                        vfileEnumvars.GetVar("Number", "", EC0Number)

                                                                                        vfileEnumvars.GetVar("Part Number", "", PartNumber)

                                                                                        vfileEnumvars.GetVar("Revision", "", Revision)

                                                                                        vfileEnumvars.GetVar("CN_Rev", "", ChangenoteRev)

                                                                                        vfileEnumvars.GetVar("CN_DevRelease", "", ChangenoteDevRelease)

                                                                                        vfileEnumvars.GetVar("CN_PDF", "", ChangenotePDF)

                                                                                        vfileEnumvars.GetVar("CN_DXF", "", ChangenoteDXF)

                                                                                        vfileEnumvars.GetVar("CN_WIP", "", WIP)

                                                                                        vfileEnumvars.GetVar("CN_STOCK", "", STOCK)

                                                                                        vfileEnumvars.GetVar("CN_FIELD", "", FIELD)

                                                                                 

                                                                                        ''''''Find PDFs'''''''''''''

                                                                                        Try

                                                                                            'Dim vfileEnumvars As IEdmEnumeratorVariable5 = poCmd.mpoExtra

                                                                                            If AffectedFile.mbsStrData2 = "Change Note Design Approval" Then

                                                                                                'Dim FileDirectory As String() = Directory.GetFiles("\\Network\GILO-TS-1\123 Folders\Drawings\")

                                                                                                'For Each FoundFile In FileDirectory

                                                                                                'If (System.IO.File.Exists("\\Network\GILO-TS-1\123 Folders\Drawings\" & FileNamePDF)) Then

                                                                                            

                                                                                  If (System.IO.File.Exists("C:\Rotron_Vault_Test2\Engineering\Design\Change Managements 2\" & FileNamePDF)) Then

                                                                                 

                                                                                                        ChangenotePDF = 1

                                                                                 

                                                                                                        v = poCmd.mpoVault

                                                                                                        vfileID = ppoData(0).mlobjectId1

                                                                                                        vFile = v.GetFileFromPath("C:\Rotron_Vault_Test2\Engineering\Design\Change Managements 2\" & FileNameEC)

                                                                                 

                                                                                                    Dim pos As IEdmPos5

                                                                                                        pos = vFolder.GetFirstFilePosition

                                                                                 

                                                                                                    If Not vFile.IsLocked Then  '

                                                                                                        Try

                                                                                                            vFile.LockFile(vFolder.ID, "", CInt(EdmLockFlag.EdmLock_Simple))

                                                                                 

                                                                                                        Catch ex As Exception

                                                                                                            MsgBox(ex.Message)

                                                                                                        End Try

                                                                                                    End If

                                                                                 

                                                                                                    '  Dim vfileEnumvars As IEdmEnumeratorVariable8 = vFile.GetEnumeratorVariable

                                                                                                    '  vfileEnumvars.CloseFile(False)

                                                                                                   '  vfileEnumvars.GetVar("CN_PDF", "", ChangenotePDF)

                                                                                                    ' vfileEnumvars.SetVar("CN_PDF", String.Empty, 1)

                                                                                                    'vfileEnumvars.CloseFile(True)

                                                                                                    'vFile.UnlockFile(vFolder.ID, "", CInt(EdmLockFlag.EdmLock_Simple))

                                                                                                End If

                                                                                                'Next

                                                                                            End If

                                                                                        Catch ex As Exception

                                                                                            MessageBox.Show(ex.Message)

                                                                                        End Try

                                                                                    End Sub

                                                                                  • Re: EPDM Prestate Transition File Check and Variable Update
                                                                                    Adon Nicholls

                                                                                    Dim FileDirectory As String() = Directory.GetFiles("C:\Rotron_Vault_Test2\Engineering\Design\Change Managements 2")

                                                                                    Added this line

                                                                                      • Re: EPDM Prestate Transition File Check and Variable Update
                                                                                        Jacob Corder

                                                                                        you need to debug this live. it will tell you what your missing and at what line and why.

                                                                                         

                                                                                        using Directory.Getfiles will not always work fyi.

                                                                                         

                                                                                         

                                                                                         

                                                                                        set project startup

                                                                                         

                                                                                        add the compiled DLL into EPDM

                                                                                         

                                                                                         

                                                                                        click add Add-In.

                                                                                         

                                                                                        find your dLL it will give you some bs error like always.

                                                                                         

                                                                                        then KILL windows explorer,  then hit debug in visual studio.

                                                                                          • Re: EPDM Prestate Transition File Check and Variable Update
                                                                                            Adon Nicholls

                                                                                            Hey again,

                                                                                            I tried this, put the file through the transition but no error showed up. I stopped it and got this at the bottom

                                                                                             

                                                                                             

                                                                                            'explorer.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

                                                                                             

                                                                                            'explorer.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\NichollsA\AppData\Local\SOLIDWORKS\SOLIDWORKS PDM\Plugins\Rotron_Vault_Test2\{FC1DDC85-8AB5-3D1E-BEFF-890BBE3684C4}222\Change Note Checker.dll'. Cannot find or open the PDB file.

                                                                                             

                                                                                             

                                                                                            'explorer.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

                                                                                            'explorer.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

                                                                                            'explorer.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

                                                                                            'explorer.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

                                                                                            'explorer.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

                                                                                            The program '[9736] explorer.exe' has exited with code -1 (0xffffffff).

                                                        • Re: EPDM Prestate Transition File Check and Variable Update
                                                          Jacob Corder

                                                          why are you implementing all of the EPDM Objects up top?

                                                          i understand you need to implement IEDMADDIN5 but the others are odd. unless something new is required.

                                                          • Re: EPDM Prestate Transition File Check and Variable Update
                                                            Ulf Stockburger

                                                            Hi Adon

                                                             

                                                            I don't want to be rude, but I suggest the following: Learn the basics and create an add-in that doesn't do anything else as implement and catch a hook. Do not extend the add-in until the existing functions work reliably and error handling is implemented.

                                                             

                                                            Last but not least, make it as easy as possible for those who want to help you. E.g. insert the source code as text, not as images.

                                                             

                                                            BiI SAP-PDM

                                                              • Re: EPDM Prestate Transition File Check and Variable Update
                                                                Adon Nicholls

                                                                Hi Ulf,

                                                                I wouldn't know where to learn the basics. I've come into a design engineer job with little coding experience and only in C, was then asked to learn this on my own and have tried to use these forums although most of the stuff is out of my league and the solidworks api websites which I can't make hide nor hair of really.

                                                                 

                                                                The other API's I've done worked by using buttons or the explorer tools menu in pdm and never threw errors like this. Again I looked for a week or two and no one had done a transitional hook that I could find.as an example or jumping off point.

                                                                 

                                                                How do I upload the code as a class file or project or? I thought images would help as people can read it without loading everything up especially as visual studio doesn't give the error itself?

                                                                 

                                                                Kind rRegards,

                                                                Adon