6 Replies Latest reply on Jun 30, 2015 2:59 PM by Lee Priest

    EPDM API - checking out a file already opened in SolidWorks

    tyty tyty
      • Is there a way to check out a document when the file is open in SolidWorks? I’m trying to check out a part or assembly from an opened drawing. The highlighted line doesn’t work if the file is opened as a reference.

          Sub epdmCheckOutFile(ByVal strFileName As String)

              Dim folder As EdmLib.IEdmFolder5 = Nothing

              Dim file As EdmLib.IEdmFile5 ' = folder.GetFile(strFileName)


              file = pdmVault.GetFileFromPath(strFileName, folder)



                  Dim RetVal As MsgBoxResult

                  RetVal = MsgBox("Do you want to check out " & file.Name, MsgBoxStyle.YesNo, "Vermeer Tools - Check Out File")

                  If RetVal = MsgBoxResult.Yes Then

                      file.LockFile(folder.ID, 0)

                  End If

              Catch ex As Exception

                  MessageBox.Show("Unable to check out " & strFileName, "File Check Out Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)

              End Try

          End Su

        • Re: EPDM API - checking out a file already opened in SolidWorks
          Adam Hoffman

          Here is what I currently use in a stand alone .exe program:


          Private Sub CheckOutFile(ByVal DrawingModel As SldWorks.ModelDoc2, ByVal FullFileNameToCheckOut As String, ByVal CurrentConFig As String)


                  Dim vault As New EdmVault5

                  Dim vaultname As String = "Your Vault Name Here"

                  vault.LoginAuto(vaultname, 0)

                  Dim userMgr As IEdmUserMgr5

                  userMgr = vault

                  Dim user As IEdmUser5

                  user = userMgr.GetLoggedInUser

                  Dim sUser As String = CStr(user.Name)


                  Dim aFolder As IEdmFolder5 = Nothing

                  Dim aFile As IEdmFile5 = vault.GetFileFromPath(FullFileNameToCheckOut, aFolder)


                  If aFile IsNot Nothing Then


                      Dim bLocked As Boolean = aFile.IsLocked


                      If bLocked = False Then




                              Dim iRelease As Integer = DrawingModel.ForceReleaseLocks()


                              If iRelease = 1 Then


                                  Dim iMyHandle As Integer = GetMyHandle()


                                  aFile.LockFile(aFolder.ID, iMyHandle, 0)


                                  iRelease = DrawingModel.ReloadOrReplace(False, DrawingModel.GetPathName, False)


                              ElseIf iRelease = 0 Then


                                  Dim bResult As DialogResult = MessageBox.Show("There Was An Error Trying To Check Out The Specified File" + vbNewLine + "Please Check Out The File And Click OK", "Check-Out Error", MessageBoxButtons.OKCancel)


                                  If bResult = Windows.Forms.DialogResult.Cancel Then



                                  End If


                              End If


                          Catch CheckOutError As Exception


                          End Try


                      ElseIf bLocked = True Then


                          Dim aLockedBy As IEdmUser5 = aFile.LockedByUser

                          Dim sLockBy As String = CStr(aLockedBy.Name)


                          If Not UCase(sLockBy) = UCase(sUser) Then


                          MessageBox.Show("The File Is Checked Out By: " + sLockBy + vbNewLine + _

                                                           "Please Ask Them To Check In The File", "Check-Out Error", MessageBoxButtons.OKCancel)


                          End If


                      End If


                  End If


              End Sub

          • Re: EPDM API - checking out a file already opened in SolidWorks
            Lee Priest

            I don't know if anyone has found this, but I couldn't get ForceReleaseLocks to work with drawing files. Turns out, this is normal behavior and you need to use the CloseAndReopen function. More info here: 2012 SOLIDWORKS API Help - CloseAndReopen Method (ISldWorks)