Hello Everyone, I'm hoping someone can please help me out. The below macro is really close to working. I am trying to create a PDM task where I can right-click on a drawing and it will run a task to open the drawing, check it out, rebuild/save, then check it back in. This macro appears to check out the file and check it back in with "Checked in by Macro" in the comments and the version is incremented, however it doesn't appear to open the file or rebuild or save it. Any help would be greatly appreciated. Thanks everyone.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim pdmVault As Object
Dim strFullPath As String
Dim strFolderPath As String
Dim strFileType As String
Dim intFileType As Integer
Dim i As Integer
Dim strFileName As String
Sub Main()
'Initialize macro
Set swApp = Application.SldWorks
strFullPath = "
strFolderPath = "
'Limit the macro to SLDDRW files
strFileType = LCase(Right(strFullPath, 6))
Select Case strFileType
Case "slddrw"
intFileType = 3
Case Else
End
End Select
'Grabs filename only
i = InStrRev(strFullPath, "\")
strFileName = Right(strFullPath, Len(strFullPath) - i)
'Create vault object
Set pdmVault = CreateObject("ConisioLib.EdmVault")
pdmVault.loginauto "[vaultName]", 0
Dim folder As Object
Set folder = pdmVault.GetFolderFromPath(strFolderPath)
Dim file As Object
Set file = pdmVault.GetFileFromPath(strFullPath, folder)
'Check out if needed
If False = file.IsLocked Then
file.LockFile folder.ID, 0
End If
'open model
Set swModel = swApp.OpenDoc(strFullPath, intFileType)
swModel.ForceRebuild3 False
swModel.Save
swApp.CloseDoc strFileName
'Check in
If True = file.IsLocked Then
file.UnlockFile 0, "Checked in by Macro"
End If
End Sub
SolidworksApi/macros