3 Replies Latest reply on Mar 8, 2017 2:14 PM by Tim Webb

    PDM, How to check out a Drawing file already open using API (VBA)

    Cad Admin

      I looked at using ForceReleaseLocks Method, but it doesn't work on drawings.

       

      I started looking into See ISldWorks::CloseAndReopen for details about closing and reopening a drawing document without unloading.  But I'm confused to its usage, the sample API, is limited in descriptive help.

        • Re: PDM, How to check out a Drawing file already open using API (VBA)
          Steve Ostrovsky

          I usually just RMB on the drawing and check it out I know I'm being a smart ass, but I couldn't resist.

           

          • Re: PDM, How to check out a Drawing file already open using API (VBA)
            Tim Webb

            Posted this as a reply on your post in API/Macros as well. This works for models/assys but not drawings. This was written in VBA and a reference was made to the PDMWorks library.

             

            1. Option Explicit 
            2.  
            3. Sub main() 
            4.  
            5.     Dim swApp                              As SldWorks.SldWorks 
            6.     Dim swDoc                              As SldWorks.ModelDoc2 
            7.     Dim strOldDocPath                      As String 
            8.  
            9.  
            10.     Set swApp = Application.SldWorks 
            11.     Set swDoc = swApp.ActiveDoc 
            12.      
            13.     strOldDocPath = swDoc.GetPathName 
            14.     Dim vault As EdmVault5 
            15.     Set vault = New EdmVault5 
            16.     Debug.Print "Vault object was set to new EdmVault5" 
            17.     Dim vaultname As String 
            18.     vaultname = vault.GetVaultNameFromPath(strOldDocPath) 
            19.     Debug.Print "Vault name = " & vaultname 
            20.     vault.LoginAuto vaultname, 0 
            21.     Debug.Print "Vault was logged in" 
            22.    
            23.     Dim file As IEdmFile5 
            24.     Dim folder As IEdmFolder5 
            25.      
            26.     Set file = vault.GetFileFromPath(strOldDocPath, folder) 
            27.     Debug.Print "File object was set: " & file.Name 
            28.     Debug.Print "Folder object was set: " & folder.LocalPath 
            29.      
            30.     If file.IsLocked = False Then 
            31.         Debug.Print "File was not locked" 
            32.         Dim iRelease As Integer 
            33.         iRelease = swDoc.ForceReleaseLocks 
            34.         Debug.Print "swDoc.ForceReleaseLocks was issued" 
            35.         If iRelease = 1 Then 
            36.             Debug.Print "swDoc.ForceReleaseLocks = 1" 
            37.             file.LockFile folder.ID, 0 
            38.             Debug.Print "File was checked out" 
            39.             Dim nRetVal As Long 
            40.             nRetVal = swDoc.ReloadOrReplace(False, swDoc.GetPathName, True) 
            41.             Debug.Print "File = " & swDoc.GetPathName 
            42.             Debug.Print "  ReloadOrReplace (0 = swComponentReloadError_e.swReloadOkay) = " & nRetVal 
            43.         ElseIf iRelease = 0 Then 
            44.             Debug.Print "swDoc.ForceReleaseLocks = 0" 
            45.             MsgBox "Unable to check out the file " & file.Name, vbOKOnly, "Error!" 
            46.         End If 
            47.     End If 
            48.    
            49. End Sub