3 Replies Latest reply on Jan 3, 2018 5:54 AM by Lasse Nielsen

    check out script is to slow

    Lasse Nielsen

      Hello forum,

       

      I'm trying to create a custom script, that allows me to clean up some data on old data cards and old custom properties

       

      So far I have created the following - almost working script. The problem is that PDM is to slow to check out the file in question, causing an error to occur when writing data to the data card. The error occurs at "pEnumVar.SetVar". How can I fix that?

       

      Best

      Lasse

       

      Option Explicit

       

      Dim swApp As SldWorks.SldWorks

      Dim pdmVault As Object

       

      Dim strFullPath As String

      Dim strFolderPath As String

      Dim strFileType As String

      Dim intFileType As Integer

       

      Dim Errors As Long

      Dim Warnings As Long

       

      Sub main()

       

          Set swApp = Application.SldWorks

       

          strFullPath = "<Filepath>"

          strFolderPath = "<Path>" & "\"

             

          strFileType = LCase(Right(strFullPath, 6))

         

          Select Case strFileType

              Case "sldprt"

                  intFileType = 1

              Case "sldasm"

                  intFileType = 2

              Case Else

                  End

          End Select

         

          Set pdmVault = CreateObject("ConisioLib.EdmVault")

          pdmVault.LoginAuto "LQN-Sandbox", 0

         

          Dim folder As Object

          Set folder = pdmVault.GetFolderFromPath(strFolderPath)

       

          Dim file As Object

          Set file = pdmVault.GetFileFromPath(strFullPath, folder)

         

          Dim pEnumVar As Object

          Set pEnumVar = file.GetEnumeratorVariable

       

          If False = file.IsLocked Then

              file.LockFile folder.ID, 0

          End If

         

          pEnumVar.SetVar "RevisionNote", "Default", "Test", False

          pEnumVar.Flush

            

          If True = file.IsLocked Then

              file.UnlockFile 0, "Checked in by Macro"

          End If

         

      End Sub

        • Re: check out script is to slow
          Alex Burnett

          I'm not sure if it would work but you could add a check before you make your data card changes similar to the following.

           

          Do While Not file.IsLocked

               'wait

          Loop

           

          The problem with this is that there is a chance you can get stuck in the while loop unless you create a timeout check to prevent it.

           

          I always prefer to use events so that the file tells me when it's in a state where I can do what I'd like but I don't see any right now within the reference dll I'm using in my add-in.

            • Re: check out script is to slow
              Lasse Nielsen

              I tried that, but unfortunately it didn't work.

              The problem seems strange to me, since I have never experienced a macro being ahead of it own event before

              • Re: check out script is to slow
                Lasse Nielsen

                Hi again.

                 

                I found the solution.

                 

                The fix is simply to make sure that the file is checked out in the code BEFORE running

                Set pEnumVar = file.GetEnumeratorVariable("")

                 

                 

                CORRECT CODE

                     If False = file.IsLocked Then

                          file.LockFile folder.ID, 0

                     End If

                   

                    Dim pEnumVar As Object

                    Set pEnumVar = file.GetEnumeratorVariable("")

                   

                    pEnumVar.SetVar "RevisionNote", "Default", "WHAT", False

                    pEnumVar.Flush

                  

                    If True = file.IsLocked Then

                        file.UnlockFile 0, "Checked in by Macro"

                    End If

                 

                 

                WRONG CODE

                    Dim pEnumVar As Object

                    Set pEnumVar = file.GetEnumeratorVariable

                 

                    If False = file.IsLocked Then

                        file.LockFile folder.ID, 0

                    End If

                   

                    pEnumVar.SetVar "RevisionNote", "Default", "Test", False

                    pEnumVar.Flush

                      

                    If True = file.IsLocked Then

                        file.UnlockFile 0, "Checked in by Macro"

                    End If