Valdas K.

Flat pattern to DXF by Macro

Discussion created by Valdas K. on Sep 10, 2020
Latest reply on Sep 11, 2020 by Deepak Gupta

Hello, is it possible to upgrade this Macro to save Flat Pattern DXF to the same folder where is the part with the same name of the part? Thank you!

 

Sample code here (it works well, just i want save location and naming to be right).

Instead of defined location to use the parts name and save to the same folder.

 

 

 

'**********************
'Copyright(C) 2020 Xarial Pty Limited
'Reference: https://www.codestack.net/solidworks-api/document/sheet-metal/export-dxf-dwg/
'License: https://www.codestack.net/license/
'**********************

Enum SheetMetalOptions_e
ExportFlatPatternGeometry = 1
IncludeHiddenEdges = 2
ExportBendLines = 4
IncludeSketches = 8
MergeCoplanarFaces = 16
ExportLibraryFeatures = 32
ExportFormingTools = 64
ExportBoundingBox = 2048
End Enum

Const OUT_PATH As String = "D:\sm.dwg"

Dim swApp As SldWorks.SldWorks

Sub main()

Set swApp = Application.SldWorks

Dim swPart As SldWorks.PartDoc

Set swPart = swApp.ActiveDoc

Dim modelPath As String

modelPath = swPart.GetPathName

If modelPath = "" Then
Err.Raise vbError, "", "Part document must be saved"
End If

If False = swPart.ExportToDWG2(OUT_PATH, modelPath, swExportToDWG_e.swExportToDWG_ExportSheetMetal, True, Empty, False, False, SheetMetalOptions_e.ExportFlatPatternGeometry + SheetMetalOptions_e.ExportBendLines, Empty) Then
Err.Raise vbError, "", "Failed to export flat pattern"
End If

End Sub

Outcomes