AnsweredAssumed Answered

Macro to export DXF of unsaved drawing.

Question asked by Daniel Sailer on Jun 25, 2017
Latest reply on Jul 9, 2017 by Daniel Sailer

Hi SolidWorks Macro specialists,

 

I have a simple macro to export drawings to DXF.

 

Dim swApp As Object

 

Dim Part As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

 

Sub main()

 

Set swApp = _

Application.SldWorks

 

Set Part = swApp.ActiveDoc

Dim myModelView As Object

Set myModelView = Part.ActiveView

myModelView.FrameState = swWindowState_e.swWindowMaximized

 

If (swApp.ActiveDoc.GetPathName = "") Then          'Check if file is saved

    MsgBox ("First save the drawing!")

    Exit Sub

End If

 

saveFileName = Left(swApp.ActiveDoc.GetPathName, Len(swApp.ActiveDoc.GetPathName) - 7) + ".dxf" ' Save as DXF

longstatus = Part.SaveAs2(saveFileName, 0, 1, 1)

End Sub

 

Now the goal is to export the drawing without saving it before. How can I get the name and Path of the parent part? This is needed for, I think it is called like "flat pattern ..." in English. In this case there is no need to save the drawing.

 

Hopefully you understand my explanation.

 

Thank you very much!

 

Daniel

Outcomes