Files
Export flat pattern as DXF Test model
Code
Module: mMain
'Demonstrates how to export a selected sheet metal body's flat pattern
'Preconditions: Sheet metal body is selected in cut list.
'Results: DXF is exported to location specified in OUTPUT_PATH.
'Notes:
'1. In order to export a single body in a multi-body sheet metal part
' you must select that flat pattern view.
'2. IPartDoc::ExportFlatPatternView doesn't allow you to export a single
' body in a multi-body sheet metal part. The alignment is also
' frequently incorrect. You can test this API call in main2().
Private Const OUTPUT_PATH As String = "C:\test.dxf"
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swPart As PartDoc
Dim swSelMgr As SelectionMgr
Dim swBody As Body2
Dim swFeat As Feature
Dim swFace As Face2
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
Set swSelMgr = swModel.SelectionManager
Set swBody = swSelMgr.GetSelectedObject6(1, -1)
Set swFeat = FindBodysFlatPattern(swBody)
If swFeat Is Nothing Then
MsgBox "Couldn't locate a flat pattern feature for selected body."
Exit Sub
End If
swFeat.Select False
swPart.ExportToDWG2 "C:\test.dxf", swModel.GetPathName, swExportToDWG_ExportSheetMetal, _
True, Empty, False, False, 1 + 4, Empty
End Sub
Private Function FindBodysFlatPattern(swBody As Body2) As Feature
Dim swFeat As Feature
Dim vFeats As Variant
Dim i As Integer
vFeats = swBody.GetFeatures
If IsEmpty(vFeats) Then Exit Function
For i = 0 To UBound(vFeats)
Set swFeat = vFeats(i)
If swFeat.GetTypeName = "FlatPattern" Then
Set FindBodysFlatPattern = swFeat
Exit Function
End If
Next i
End Function
Sub main2()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swPart As PartDoc
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
swPart.ExportFlatPatternView OUTPUT_PATH, Empty
End Sub