Below is a simple macro to export the current drawing as a DXF file to N:\DXF. As you can see, it names the DXF "Draw1.dxf". How can I edit the macro to so the dxf filename is the same filename as the SolidWorks drawing, which is our part numbering system. Thanks in advance. Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long Dim Annotation As Object Dim Gtol As Object Dim DatumTag As Object Dim FeatureData As Object Dim Feature As Object Dim Component As Object Sub main() Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Part.SaveAs2 "N:\DXF\Draw1.DXF", 0, True, False End Sub
This should work............. Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long Dim Annotation As Object Dim Gtol As Object Dim DatumTag As Object Dim FeatureData As Object Dim Feature As Object Dim Component As Object Dim PartTitle As String Sub main() Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc PartTitle = Part.GetTitle Part.SaveAs2 "N:\DXF\" & PartTitle & ".DXF", 0, True, False End Sub
Dim swApp As Object Dim Part As Object dim partitle as string dim partitlelen as integer dim partName as string Sub main() Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc partitle = part.gettitle partitlelen = len(partitle) partname = left(partitle,partitlelen - (partitlelen -7)) Part.SaveAs2 "N:\DXF\" & partname & ".DXF", 0, True, False End Sub
Thanks! Works great. One last question, is there a command to add to this that would scale the drawing view 1:1 automatically before exporting as a DXF?
Can we add a suffix to each part number while running this macro? In our case "-01" to identify the first configuration. Thanks in advance.
Dim swApp As Object Dim Part As Object dim partitle as string dim partitlelen as integer dim partName as string Sub main() Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc partitle = part.gettitle partitlelen = len(partitle) partname = left(partitle,partitlelen - (partitlelen -7)) 'YOU CAN ADD A LINE LIKE THIS SUFFIX = "-1" Part.SaveAs2 "N:\DXF\" & partname & SUFFIX & ".DXF", 0, True, False End Sub If you need to get your config names Dim Config As SldWorks.configuration Set Config = Part.GetActiveConfiguration ConfigName = Config.Name Part.SaveAs2 "N:\DXF\" & partname & ConfigName & ".DXF", 0, True, False
I couldnt get the 1:1 scale code to work. Maybe I placed it in the wrong part of the macro. Can you explain. Thanks. I also wanted to know if its possible to close the drawing without saving after the DXF file has been created. Thanks.
You have to rebuild after the 1:1 You have to do a rebuild you have finished scaling. Use the sub below. This way if you want .25 scale or 1 or 2 or 50 you can call it from another sub and specify the scale Sub viewScale(MyScale As Double) Dim swView As SldWorks.View Dim swApp As SldWorks.SldWorks Dim Part As DrawingDoc Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Set swView = Part.GetFirstView 'this while statement will traverse every view on the sheet While Not swView Is Nothing swView.ScaleDecimal = MyScale Set swView = swView.GetNextView Wend Part.EditRebuild End Sub This should do it. I think that if you want to save you have to do a Part.Save before CloseDoc Dim ModelDocument as SldWorks.ModelDoc2 Set ModelDocument = Part swApp.CloseDoc ModelDocument.GetTitle