Valdas K.

Saving DXF with configuration name

Discussion created by Valdas K. on Sep 11, 2020
Latest reply on Sep 12, 2020 by Wayne Matus

Hello. I am trying to save a flat pattern, but I need configuration name to be in exported DXF

I am trying to make a code, where name of exported DXF consist of:
File location + Name of Active Configuration + Custom Specified property of configuration  + ".dxf". 

Exported dxf should save to the same folder where the active file is.

Is it possible to make?

 

 

Example of code I am using:

 

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

Sub main()
Set swApp = Application.SldWorks
Dim swPart As SldWorks.PartDoc
Set swPart = swApp.ActiveDoc

Dim modelPath As String
Dim OUT_PATH As String


Dim strPath As String
Dim strFile As String
Dim ConfigName As String

strPath = swPart.GetPathName
FileLocation = Left(strPath, Len(strPath) - InStrRev(strPath, "\") - 1) 'Get folder location

'MsgBox "The value of i is " & strFile, vbInformation

modelPath = swPart.GetPathName
MD01 = Left(modelPath, InStrRev(modelPath, ".") - 4) ' remove 4 symbol text from end
OUT_PATH = FileLocation & ConfigName & ".dxf"


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