I made an code to create a dxf file starting from a 2D document in solidworks.
So what I bassically do:
I create a dxf sheet
add the flat pattern
add part number to it
And then I wanted the sheet called dxf to be saved to a location with the SW file name.
In my save loop, I dont understand why the method SwPart.SaveAs3 gives me a false result altough the file is saved. I expect a true feedback, but i got a false.
Below I just added a longstatus to see how the part is saved.
The reason to get this feedback is to implement a save loop that warns me if the part is not correctly saved.
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FileName As String
Dim FileNameNoExt As String
Dim DxfPathName As String
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
' Zoom To Fit
Part.ViewZoomtofit2
boolstatus = Part.NewSheet3("DXF", 12, 13, 1, 1, False, "C:ProgramDataSolidWorksSOLIDWORKS 2024langenglishsheetformata0 - iso.slddrt", 6, 6, "Same as sheet specified in Document Properties")
'First hide bend notes
'insert flat pattern view
'show bend notes again
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swShowSheetMetalBendNotes, 0, False)
Dim myView As Object
Set myView = Part.DropDrawingViewFromPalette2("Flat pattern", 3, 3, 0)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swShowSheetMetalBendNotes, 0, True)
'add file name
Set Part = swApp.ActiveDoc
Set Part = swApp.ActiveDoc
Dim myAnnotation As Object
Set myAnnotation = Part.Extension.InsertAnnotationFavorite("W:10 ALGEMEENSolidworks spinnekop configurationNote LibraryPart_number.sldnotestl", 3, 3, 0)
'Retreive name and convert
Set Model = swApp.ActiveDoc
FileName = Model.GetTitle
FileNameNoExt = Left(FileName, Len(FileName) - 6)
DxfPathName = "D:" + FileNameNoExt + ".dxf"
MsgBox (DxfPathName)
'save loop & control
Set swPart = swApp.ActiveDoc
modelPath = swPart.GetPathName
If modelPath = "" Then
Err.Raise vbError, "", "Part document must be saved"
End If
longstatus = swPart.SaveAs3("D:" + FileNameNoExt + ".dxf", swSaveAsCurrentVersion, swSaveAsOptions_Silent + swSaveAsOptions_Copy)
MsgBox (longstatus)
If False = swPart.SaveAs3("D:" + FileNameNoExt + ".dxf", swSaveAsCurrentVersion, swSaveAsOptions_Silent + swSaveAsOptions_Copy) Then
Err.Raise vbError, "", "Failed to export flat pattern"
End If
Set swApp = Application.SldWorks
End Sub
I expect an answer how the method need to be changed so i get true back from the method when de file is saved.
user26503129 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.