AnsweredAssumed Answered

Macro to create DXF of each Configuration of sheet metal part

Question asked by Geoff Moss on Aug 16, 2018

I have a simple macro that takes an active part file, and checks if each body is sheet metal, and if so creates a DXF of it. I want to modify it to create a DXF of each configuration, after checking if that configuration is a sheet metal body.


Typical usage situation: SLDPRT with configuration named MASTER which is a multi-body sheet metal part. Then a series of configurations, each named according to the respective part number, each one using BODY-DELETE features to remove all but one sheet metal body.


I would like the macro to traverse each configuration, check if the resulting model is a sheet metal body, and if so export the flat pattern to DXF. Here is my code for doing so on a single-configuration multi-body part:


Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim featureMgr As SldWorks.FeatureManager
Dim feat As SldWorks.Feature
Dim sheetMetalFolder As SldWorks.sheetMetalFolder
Dim swPart As SldWorks.PartDoc

Dim swConfigMan As IConfigurationManager
Dim swConfig As Configuration

Dim swObj As Object
Dim swBody As Body2
Dim nBendState As Long
Dim varBodies As Variant

Dim featArray As Variant
Dim i As Long, nCount As Long

Option Explicit

Sub main()
    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    If Not swModel.GetType = swDocPART Then
        Debug.Print "Must be a part file; exiting..."
        Exit Sub
    End If
    Set swPart = swModel
    Set featureMgr = swModel.FeatureManager
    varBodies = swPart.GetBodies2(swBodyType_e.swSolidBody, True)
    For i = 0 To UBound(varBodies)
        Set swBody = varBodies(i)
        If (swBody.IsSheetMetal) Then
            Debug.Print "Sheet metal found!"
            Set featureMgr = swModel.FeatureManager
            Set sheetMetalFolder = featureMgr.GetSheetMetalFolder

            Set swConfig = swModel.GetActiveConfiguration
            Debug.Print "Configuration: " & swConfig.Name
'            Debug.Print "No sheet metal found..."
        End If
    Next i
End Sub