AnsweredAssumed Answered

Marco to save pdf/dwg in specific directory

Question asked by Robert H. on Aug 4, 2017
Latest reply on Feb 7, 2018 by Robert H.

Hi all

 

am looking to get write/modify a macro to save pdf and dwg to a specific directory , expect i can not get the marco to save them in the right folders, i can get them to be saved out on level up  but i can not seam to go down one again to save the PDF/DWG in there respective folders - did try  + "/PDF" + but it doesn't seam to be working

instead it the macro just adds PDF to the file name , very frustrating, am sure it something simple am missing !!

 

Thank you

 

Robert

 

eg

Drawing directory

\430_F12 GLASS SHELVING\CAD FILES\ ( soildworks drawing file)

 

PDF / DWG directory

 

430_F12 GLASS SHELVING\PDF

 

430_F12 GLASS SHELVING\DWG

 

 

Code:

 

Dim swApp           As SldWorks.SldWorks

Dim swModel         As SldWorks.ModelDoc2

Dim swDraw          As SldWorks.DrawingDoc

Dim Filepath        As String

Dim FileName        As String

Dim Drawingno       As String

Dim Rev             As String

Dim Title           As String

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Sub main()

 

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

 

 

' Check to see if a drawing is loaded.

 

 

If (swModel Is Nothing) Or (swModel.GetType <> swDocDRAWING) Then

 

 

swApp.SendMsgToUser ("To be used for drawings only, Open a drawing first and then TRY!")

 

 

' If no model currently loaded, then exit

 

 

 

 

Exit Sub

 

 

End If

 

Set swDraw = swModel

Set SWmoddoc = swApp.ActiveDoc

 

 

Filepath = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\") - 10)

If Dir(Filepath & "PDF", vbDirectory) = "" Then ' Change Sub folder Name here

MkDir Filepath + "PDF" ' Change Sub folder Name here

End If

 

 

If Dir(Filepath & "DWG", vbDirectory) = "" Then ' Change Sub folder Name here

MkDir Filepath + "DWG" ' Change Sub folder Name here

End If

 

 

 

 

 

 

Drawingno = SWmoddoc.CustomInfo("Drawing No.")

 

 

Rev = SWmoddoc.CustomInfo("version")

 

 

Title = SWmoddoc.CustomInfo("Title")

 

 

 

 

 

 

swDraw.SaveAs (Filepath + Drawingno + "_#" + Rev + "_" + Title + ".PDF")

swDraw.SaveAs (Filepath + Drawingno + "_#" + Rev + "_" + Title + ".DWG")

 

 

End Sub

Outcomes