AnsweredAssumed Answered

export to DXF, PDF, and then save the file

Question asked by Ryan Bigler on Jan 28, 2014
Latest reply on Jun 20, 2015 by Arif Akbas

I use 1 to save the current drawing to a dxf, pdf, and I have added in a save function for the drawing file itself.  I was wondering if you could help me with a macro for saving each drawing sheet into different files, but with naming the file after what the sheet name is?  I don't need one with revisions or anything of that sort.  I would also like to be able to save the pdf files with separate files rather than having it all in the same file.  This makes it easier to send different files to different machine shops.   Down below is the macro that I currently use.  I have since modified it to save as DXF instead of DWG as well as to do a save of the file when done.  Any help would be greatly appreciated.







'File Save As PDF & DWG.swp -------------03/18/13


'Description: Macro to save active drawing as PDF and DWG.

'Precondition: Any active drawing to be saved.

'Postcondition: Active drawing will be saved as PDF and DWG in the same location as drawing.


' Please back up your data before use and USE AT OWN RISK


' This macro is provided as is.  No claims, support, refund, safety net, or

' warranties are expressed or implied.  By using this macro and/or its code in

' any way whatsoever, the user and any entities which the user represents,

' agree to hold the authors free of any and all liability.  Free distribution

' and use of this code in other free works is welcome.  If any portion of

' this code is used in other works, credit to the authors must be placed in

' that work within a user viewable location (e.g., macro header).  All other

' forms of distribution (i.e., not free, fee for delivery, etc) are prohibited

' without the expressed written consent by the authors.  Use at your own risk!

' ------------------------------------------------------------------------------

' Written by: Deepak Gupta (

' -------------------------------------------------------------------------------




Dim swApp       As SldWorks.SldWorks
Dim swModel     As SldWorks.ModelDoc2
Dim swDraw      As SldWorks.DrawingDoc
Dim Filepath    As String
Dim FileName    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


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


FileName = Left(swDraw.GetTitle, Len(swDraw.GetTitle) - 9)


swDraw.SaveAs (Filepath + FileName + ".PDF")

swDraw.SaveAs (Filepath + FileName + ".DXF")



End Sub