4 Replies Latest reply on Jul 19, 2017 1:33 PM by John Stoltzfus

    Creating DXF and PDF files from SW Drawings

    Ryan Dayton 0599

      Are there any ways to export your SW drawings as DXF and PDF's automatically and for them to automatically update when you change the drawing?

        • Re: Creating DXF and PDF files from SW Drawings
          John Stoltzfus

          I'm thinking you could using macros and you would need a macro to run when you either close or save the drawing...

           

          Maybe

           

          Deepak Gupta

          Amen Allah Jlili

          Keith Rice

           

          Can help

          • Re: Creating DXF and PDF files from SW Drawings
            Deepak Gupta

            As John, mentioned, a macro can be made to do that.

            • Re: Creating DXF and PDF files from SW Drawings
              Bernie Daraz

              I have this one that I've been using since 2011. The advantages in this macro are that it also saves a copy of the iges file as well AND it also saves those files to your SW file in the Design Binder. We used contract manufacturers all over the world so it was imperative that we had a system that worked. That may not be required in your workflow and disabling those functions is as easy as commenting out the lines as noted.

               

              I have attached the macro file and pasted the text below. This macro would need to be run again to update the files. Though I'm not sure this will actually replace the files as I have never done so.

               

              'This macro saves current drawing to PDF, IGS and DXF. Precondition is that you save an IGS file using the EXACT same name as the drawing file.

              'Then this macro also inserts these files into the Design Binder

              'Pack and Go will then add these files at the same time

               

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

               

              Option Explicit

                  Dim swApp                   As SldWorks.SldWorks

                  Dim swModel                 As SldWorks.ModelDoc2

                  Dim Linked                  As Boolean

                  Dim sPathName               As String

                  Dim nErrors                 As Long

                  Dim nWarnings               As Long

                  Dim nRetval                 As Long

                  Dim bShowMap                As Boolean

                  Dim swModelDocExt           As SldWorks.ModelDocExtension

                  Dim swExportData            As SldWorks.ExportPdfData

                  Dim filename                As String

                  Dim iPathName               As String

                  Dim boolstatus              As Boolean

                  Dim boolstatus1             As Boolean

                  Dim lErrors                 As Long

                  Dim lWarnings               As Long

                  Dim bRet                    As Boolean

                 

                     

              Sub main()

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

               

                  ' Strip off SolidWorks drawing file extension (.slddrw)

                  ' and add DXF file extension (.dxf)

                  sPathName = swModel.GetPathName

                  sPathName = Left(sPathName, Len(sPathName) - 6)

                  sPathName = sPathName + "DXF"

                  ' Show current settings

                 

              '   If swModel Is Nothing Then MsgBox "A Part or Assembly file must be open", vbExclamation: End

              ' the above line needs to be modified to check for the precondition of an igs file.

               

                  ' Turn off showing of map

                  bShowMap = swApp.GetUserPreferenceToggle(swDXFDontShowMap)

                  Set swModelDocExt = swModel.Extension

                  Set swExportData = swApp.GetExportFileData(swExportPDFData)

                  filename = swModel.GetPathName

                  filename = Strings.Left(filename, Len(filename) - 6) & "PDF"

                  ' Create IGS filename - comment out if not required

                  iPathName = Strings.Left(filename, Len(filename) - 3) & "IGS"

                 

                  boolstatus1 = swExportData.SetSheets(swExportData_ExportAllSheets, 1)

                  boolstatus1 = swModelDocExt.SaveAs(filename, 0, 0, swExportData, lErrors, lWarnings)

                 

                  swApp.SetUserPreferenceToggle swDXFDontShowMap, False

               

                  bRet = swModel.SaveAs4(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)

                  If bRet = False Then

                      nRetval = swApp.SendMsgToUser2("Problems saving file.", swMbWarning, swMbOk)

                  End If

                 

                  'Save files to Design Binder

                  'comment out the following lines if you don;t wish to save to the design binder in SW

                 

                  boolstatus = swModelDocExt.SelectByID2("Design Binder", "DOCSFOLDER", 0, 0, 0, False, 0, Nothing, 0)

                     swModelDocExt.InsertAttachment filename, False

                     swModelDocExt.InsertAttachment sPathName, False

                     swModelDocExt.InsertAttachment iPathName, False

                    

                     If boolstatus1 Then

                      MsgBox "Save as PDF/DXF and Added .PDF .DXF .IGS to Design Binder successful."

                  Else

                      MsgBox "Save as PDF failed, Error code:" & lErrors '

                  End If

                 

                  'End Save files to Design Binder sub

                 

                  ' Restore old setting

                  swApp.SetUserPreferenceToggle swDXFDontShowMap, bShowMap

              End Sub

               

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