-
Re: Dir not working on drawings I never opened
Artem Taturevych Jun 24, 2018 9:20 PM (in response to Alex Caicedo)This file is not cached in PDM local folder so it doesn't exist on your drive - that's why it is failing. You need to create local copies. Either use IEdmFile5::GetFileCopy or IEdmBatchGet from PDM API or just get the local cache from user interface in your vault.
-
Re: Dir not working on drawings I never opened
Jason Kerns Jun 26, 2018 4:37 PM (in response to Alex Caicedo)Dim vault As EdmVault5
Dim Nfile As IEdmFile5
Dim Vfolder As IEdmFolder5
Sub main()
Set vault = New EdmVault5
'CHANGE THIS TO YOUR VAULT NAME
If Not vault.IsLoggedIn Then
vault.LoginAuto "PDM VAULT NAME GOES HERE", 0
End If
Set Nfile = vault.GetFileFromPath("FilePath", vfolder)
Nfile.GetFileCopy 0, 0
'do stuff
end sub
-
Re: Dir not working on drawings I never opened
Alex Caicedo Jun 27, 2018 3:20 PM (in response to Jason Kerns)Thanks Jason,
I updated the code and it seems to run fine, but not sure what to do after that... I'm not experienced with EDM or GetFileFromPath functions. Do I just substitute "Nfile" from your code for "Filename" in my original code? For example, to open the part file I was using:
Set swApp = Application.SldWorks
Set swObj = swApp.OpenDoc6(Filename, Ftype, swOpenDocOptions_Silent, "", nErrors, nWarnings)
I replaced "Filename" with "Nfile" but getting a type mismatch.... do you know how I can open the model after the line Nfile.GetFileCopy?
thanks,
-
Re: Dir not working on drawings I never opened
Jason Kerns Jun 27, 2018 3:37 PM (in response to Alex Caicedo)Hi Alex,
If you can send me, or post your code I can update it.
"Filename" does not need to be replaced with "Nfile".
"Filename" should be assigned before the "Set Nfile ..." line then you have a cached file from PDM.
-
Re: Dir not working on drawings I never opened
Alex Caicedo Jun 27, 2018 3:54 PM (in response to Jason Kerns)Hey Jason,
See below. The bold items are what I just added from your first post... just not sure where/how to use the Nfile.
Sub BatchPDFconvert()
Load PNlist_userform
PNlist_userform.Show
HelpMsg = ""
PNarray = Split(PNlist_userform.PNinput, vbCrLf)
PNlength = UBound(PNarray)
sPath = SelectFolder("Select Folder Where Drawings Are Located", "")
If sPath = "" Then
End
End If
sPath = sPath + "\"
dPath = SelectFolder("Select Folder to Store PDFs", "")
If dPath = "" Then
End
End If
dPath = dPath + "\"
Dim vault As EdmVault5
Dim Nfile As IEdmFile5
Dim Vfolder As IEdmFolder5
If Not vault.IsLoggedIn Then
vault.LoginAuto "PAS-EPDM", 0
End If
Set swApp = Application.SldWorks
For i = 0 To PNlength
sFilename = Dir(sPath & PNarray(i) & ".slddrw") ''NOT OPENING FILES THAT HAVE NEVER BEEN VIEWED
Set Nfile = vault.GetFileFromPath(sFilename)
Nfile.GetFileCopy 0, 0
If sFilename = "" Then
HelpMsg = HelpMsg & PNarray(i) & vbNewLine
GoTo NextIncr
End If
Set swDraw = swApp.OpenDoc6(sPath + sFilename, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings)
Set swDraw = swApp.ActiveDoc
dFileName = Mid(swDraw.GetPathName, 1 + InStrRev(swDraw.GetPathName, "\"))
dFileName = Left(dFileName, InStrRev(dFileName, ".") - 1)
swDraw.SaveAs3 dPath & dFileName & ".PDF", 0, 0
swApp.QuitDoc swDraw.GetPathName
Set swDraw = Nothing
NextIncr:
Next i
If HelpMsg <> "" Then
MsgBox "Drawings that were not found in file path " & vbNewLine & sPath & vbNewLine _
& HelpMsg & "Re-run macro with new location for drawings above.", , "Error Report"
End If
-
Re: Dir not working on drawings I never opened
Jason Kerns Jun 27, 2018 4:05 PM (in response to Alex Caicedo)I see this is missing. replace your line with mine.
Set Nfile = vault.GetFileFromPath(sFilename, Vfolder)
-
Re: Dir not working on drawings I never opened
Alex Caicedo Jun 27, 2018 4:38 PM (in response to Jason Kerns)I am still getting an error on the Nfile.GetFileCopy line: "Object variable or With block variable not set."
I condensed the code so I can just work on this section.. any ideas?
Dim vault As EdmVault5
Dim Nfile As IEdmFile5
Dim Vfolder As IEdmFolder5
Dim swApp As Object
Dim sFilename As String
Dim sPath As String
Sub main()
Set vault = New EdmVault5
'CHANGE THIS TO YOUR VAULT NAME
If Not vault.IsLoggedIn Then
vault.LoginAuto "PAS-EPDM", 0
End If
sPath = "C:\PAS-EPDM\Aquatic Systems\ 2018\CLEANERS\CAD\"
sFilename = Dir(sPath & "360400" & ".slddrw")
'MsgBox sFilename
Set Nfile = vault.GetFileFromPath(sFilename, Vfolder)
Nfile.GetFileCopy 0, 0 'ERROR
Set swApp = Application.SldWorks
Set swDraw = swApp.OpenDoc6(sPath + sFilename, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings)
Set swObj = swApp.ActiveDoc
'do stuff
End Sub
-
Re: Dir not working on drawings I never opened
Artem Taturevych Jun 27, 2018 11:36 PM (in response to Alex Caicedo)Change
sFilename = Dir(sPath & "360400" & ".slddrw")
to
sFilename = sPath & "360400" & ".slddrw"
-
Re: Dir not working on drawings I never opened
Alex Caicedo Jun 28, 2018 8:47 AM (in response to Artem Taturevych)So I think that fixed the error on the Nfile.GetFileCopy, but I am now getting an error on the line that is supposed to open the drawing... its a type mismatch error.
Set swDraw = swApp.OpenDoc6(sPath + sFilename, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings)
Is there a better way to open the drawing?
thanks,
-
Re: Dir not working on drawings I never opened
Artem Taturevych Jun 28, 2018 4:54 PM (in response to Alex Caicedo)Set swDraw = swApp.OpenDoc6(sPath + sFilename, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings)
Should be
Set swDraw = swApp.OpenDoc6(sFilename, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings)
-
Re: Dir not working on drawings I never opened
Alex Caicedo Jun 29, 2018 8:31 AM (in response to Artem Taturevych)I am still getting a Type mismatch error on the Set swDraw line. Just to make sure I don't have anything else incorrect, here is what I am running.
Dim vault As EdmVault5
Dim Nfile As IEdmFile5
Dim Vfolder As IEdmFolder5
Dim swApp As Object
Dim sFilename As String
Dim sPath As String
Dim swDraw As ObjectSub main()
Set vault = New EdmVault5
'CHANGE THIS TO YOUR VAULT NAME
If Not vault.IsLoggedIn Then
vault.LoginAuto "PAS-EPDM", 0
End IfsPath = "C:\PAS-EPDM\Aquatic Systems\ 2018\CLEANERS\CAD\"
sFilename = sPath & "371998" & ".slddrw"
'MsgBox sFilename
Set Nfile = vault.GetFileFromPath(sFilename, Vfolder)
Nfile.GetFileCopy 0, 0Set swApp = Application.SldWorks
Set swDraw = swApp.OpenDoc6(sFilename, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings)'do stuff
End Sub
-
Re: Dir not working on drawings I never opened
Jason Kerns Jun 29, 2018 11:55 AM (in response to Alex Caicedo)Dim vault As EdmVault5
Dim Nfile As IEdmFile5
Dim Vfolder As IEdmFolder5
Dim swApp As Object
Dim sFilename As String
Dim sPath As String
Dim swDraw As SldWorks.ModelDoc2
Dim nErrors As Long
Dim nWarnings As Long
Sub main()
Set vault = New EdmVault5
'CHANGE THIS TO YOUR VAULT NAME
If Not vault.IsLoggedIn Then
vault.LoginAuto "PAS-EPDM", 0
End If
sPath = "C:\PAS-EPDM\Aquatic Systems\ 2018\CLEANERS\CAD\"
sFilename = sPath & "371998" & ".slddrw"
Debug.Print sFilename
Set Nfile = vault.GetFileFromPath(sFilename, Vfolder)
Nfile.GetFileCopy 0, 0
Set swApp = Application.SldWorks
Set swDraw = swApp.OpenDoc6(sFilename, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings)
'do stuff
End Sub
-
Re: Dir not working on drawings I never opened
Alex Caicedo Jun 29, 2018 11:59 AM (in response to Jason Kerns)SUCCESS!!... wow, really dumb error by me, sorry guys.
huge thanks, this was a HUGE help!
-
-
-
-
-
-
-
-
-
-
-