You have an assembly with 40 sheet metal parts and 15 structural components. You need STEP files for each part for your supplier, and DXF flat patterns for your laser subcontractor. SolidWorks has no built-in “batch export as individual STEP/DXF files” command. You have two approaches: the system options SaveAs at the assembly level, or a macro that loops over components with OpenDoc6 and SaveAs. They produce different outputs and serve different use cases.

What “System Options” SaveAs Actually Does

When you open an assembly and use File > Save As > STEP AP214 (or AP203/AP242), SolidWorks exports the entire assembly into a single STEP file. The STEP file contains:

  • One STEP PRODUCT entity for each unique part file referenced by the assembly
  • NEXT_ASSEMBLY_USAGE_OCCURRENCE entities linking parent assemblies to their children — this is the assembly tree in STEP form
  • Geometry for each PRODUCT expressed as MANIFOLD_SOLID_BREP entities (AP203) or ADVANCED_BREP_SHAPE_REPRESENTATION with color and layer data (AP214)
  • Transformation matrices (AXIS2_PLACEMENT_3D) giving each component’s position in the assembly coordinate system

The result is one STEP file representing the complete assembly. Your supplier can open it and see the full assembly structure with all parts in their correct positions.

For most supplier exchange workflows where the recipient needs to see the assembled product or manufacture a mating component, this is exactly right. For a supplier who needs to manufacture 40 individual sheet metal parts from your design, it’s the wrong output — they receive one file containing all 40 parts, with geometry entangled in a shared coordinate space, rather than 40 separate files they can route to their workcells individually.

The system options also control the STEP version. Tools > Options > Import/Export > STEP lets you select AP203, AP214, or AP242. When exporting from the assembly, SolidWorks uses whatever is set here — there is no per-export version selection in the GUI. If your workflow mixes AP214 and AP242 (AP214 for geometry-only, AP242 for PMI-carrying files), you need to change the system option between exports, which is a problem in automated pipelines.

For the full breakdown of which STEP version carries which data and when to use each, the STEP AP203 vs AP214 vs AP242 comparison covers the entity-level differences and the SolidWorks API user preference IDs that control the version.

The Macro Loop Approach — Individual Files

For individual part STEP files (one .step per component), a macro that loops over assembly components and exports each one separately is the only path SolidWorks gives you natively.

The pattern:

Dim swApp As SldWorks.SldWorks
Dim swAssy As SldWorks.AssemblyDoc
Dim vComps As Variant
Dim swComp As SldWorks.Component2

Set swApp = Application.SldWorks
Set swAssy = swApp.ActiveDoc

vComps = swAssy.GetComponents(False)  ' False = top-level only

Dim i As Integer
For i = 0 To UBound(vComps)
    Dim comp As SldWorks.Component2
    Set comp = vComps(i)
    
    If comp.GetSuppression() <> swComponentSuppression_e.swComponentSuppressed Then
        Dim srcPath As String
        srcPath = comp.GetPathName()
        
        Dim lErrors As Long, lWarnings As Long
        Dim swPart As SldWorks.ModelDoc2
        
        ' Open silently — no document loading UI
        Set swPart = swApp.OpenDoc6(srcPath, _
            swDocumentTypes_e.swDocPART, _
            swOpenDocOptions_e.swOpenDocOptions_Silent, _
            "", lErrors, lWarnings)
        
        If Not swPart Is Nothing Then
            ' Build output path
            Dim outPath As String
            outPath = "C:\export\step\" & comp.Name2 & ".step"
            
            ' Clear selection before SaveAs
            swPart.ClearSelection2 True
            
            ' Export via extension
            Dim bResult As Boolean
            bResult = swPart.Extension.SaveAs(outPath, _
                swSaveAsVersion_e.swSaveAsCurrentVersion, _
                swSaveAsOptions_e.swSaveAsOptions_Silent, _
                Nothing, lErrors, lWarnings)
            
            swApp.CloseDoc srcPath
        End If
    End If
Next i

Several things in this code are non-obvious and matter for correctness.

The Silent Open — What It Actually Does

swOpenDocOptions_e.swOpenDocOptions_Silent suppresses the UI dialogs that normally appear when opening a document: the “Resolve/Lightweight?” prompt, the missing references dialog, the “file newer than last save” warning. It does not prevent the document from loading into SolidWorks. The part file opens as a full document in memory — it’s visible in the SolidWorks title bar and appears in the open documents list.

If you’re running this macro from within SolidWorks (in-process VBA), the user will see documents opening briefly. If you’re running it as a standalone executable using a separate SldWorks.SldWorks COM instance, the documents open in whatever SolidWorks session that instance controls. Either way, the document is live in memory between OpenDoc6 and CloseDoc.

The SolidWorks API has no true “headless” open equivalent — there is no option that loads a file for read/export purposes without fully initializing the document model. This means memory footprint scales with assembly size. For a 500-part assembly, running a macro loop that opens every part sequentially will hold one document in memory at a time (since you close after each export), which is manageable, but the sequential nature means runtime is proportional to the number of components times the average per-file export time.

For a faster approach where in-process speed is critical, see the comparison in in-process vs standalone SolidWorks API. An in-process add-in can handle the document events and avoid the COM marshaling overhead that slows down standalone macro loops on large assemblies.

ClearSelection2 Before SaveAs

The line swPart.ClearSelection2 True before the SaveAs call is mandatory, not optional.

SolidWorks IModelDocExtension::SaveAs checks whether there is an active selection when the export is requested. If faces or bodies are selected, SolidWorks exports only the selected geometry, not the full model. If you call SaveAs while, for example, the shell of the assembly component happens to have a face selected (which can happen when resolving a previously lightweight component), your STEP file contains only that face — no error is raised, no warning is logged, the STEP file is written with partial geometry and the lErrors parameter stays at zero.

ClearSelection2 True clears all selected entities in the document, including sketch entities. Always call it before any SaveAs export call in a macro loop. This is one of the SolidWorks API silent failures that produces hard-to-diagnose results — the export appears to succeed, the file exists, but it contains wrong geometry.

The SaveAs Method — Old vs Current

The code above uses IModelDocExtension::SaveAs, which is the current preferred signature:

swPart.Extension.SaveAs(fileName, version, saveAsOptions, pExportData, errors, warnings)

The older IModelDoc2::SaveAs4 is deprecated but still functional:

swPart.SaveAs4(fileName, version, saveAsOptions, pExportData, pAdvancedSaveAsData, errors, warnings)

Both write the STEP file. The pExportData parameter is Nothing for STEP exports — the STEP version and options are taken from the system options (Tools > Options > Import/Export > STEP). For DXF flat pattern exports, pExportData must be an IExportPdfData-like structured object (ExportFlatPatternView bitmask), which is handled differently.

Use Extension.SaveAs in new code. SaveAs4 exists for compatibility with macros written before 2017.

DXF Batch Export — Why It Always Needs a Macro

For DXF flat patterns, there is no “system options” equivalent that gives you individual flat pattern DXF files from an assembly. The assembly-level Save As for DXF produces an isometric projection DXF of the assembly — essentially a drawing view, not a flat pattern. This is rarely what manufacturing needs.

The correct approach for flat pattern DXF is the macro loop, but the export call is different from STEP. For flat patterns, the export is driven through the sheet metal feature, not through a generic SaveAs:

' After opening the part silently:
Dim swSheetMetal As SldWorks.SheetMetal
Dim swFeat As SldWorks.Feature
Dim bFound As Boolean

' Find the flat pattern feature
Set swFeat = swPart.FirstFeature()
Do While Not swFeat Is Nothing
    If swFeat.GetTypeName2() = "FlatPattern" Then
        bFound = True
        Exit Do
    End If
    Set swFeat = swFeat.GetNextFeature()
Loop

If bFound Then
    ' Use ExportFlatPatternView for DXF
    Dim lOptions As Long
    ' swExportFlatPatternViewOptions_e bitmask:
    ' 1 = Geometry, 2 = BendLines, 4 = BendNotes, 8 = SketcLines, 16 = Thickness
    lOptions = 1 Or 2 Or 4  ' Geometry + BendLines + BendNotes

    Dim outDxf As String
    outDxf = "C:\export\dxf\" & comp.Name2 & ".dxf"
    
    Dim bDxfResult As Boolean
    bDxfResult = swPart.Extension.SaveAs(outDxf, _
        swSaveAsVersion_e.swSaveAsCurrentVersion, _
        swSaveAsOptions_e.swSaveAsOptions_Silent, _
        Nothing, lErrors, lWarnings)
End If

The DXF output from this macro contains whatever entities are configured in Tools > Options > Export > DXF/DWG > Flat Pattern. These settings are global and apply to every export in the loop — which is the same problem as with STEP: per-file export settings require changing system options between exports, which is not thread-safe and causes issues in any parallel execution.

If you need per-assembly consistent DXF output without system option changes between files, an add-in that sets the export options programmatically (via ISldWorks::SetUserPreferenceIntegerValue or the export data objects) before each SaveAs call is the right architecture. The DXF export settings that don’t persist post covers exactly this: the API calls that pin the settings within a macro session without relying on the global system options state.

CadShift handles the layer and entity configuration per-export at the add-in level, so the settings are applied consistently regardless of what the user has set in Tools > Options. This is the practical solution for shops that need to run batch DXF export as a production pipeline step rather than a one-off macro.

Sub-Assembly Components — GetComponents Depth

The GetComponents(False) call in the macro above returns only top-level components. For an assembly with sub-assemblies, the top-level component is a .sldasm file — its path via comp.GetPathName() points to the sub-assembly, not to the individual parts inside it.

For a flat export of all leaf-level parts regardless of assembly depth:

' GetComponents(True) returns all components recursively
vComps = swAssy.GetComponents(True)

With True, you get every component at every level, including the same part appearing multiple times if it’s used in multiple sub-assemblies. You’ll want to deduplicate by GetPathName() before running the export loop — otherwise you export the same part file multiple times and the later exports overwrite the earlier ones (or add a suffix convention for instances of the same part used in different sub-assemblies).

Dim exportedPaths As New Collection
' Check before adding to export list:
Dim pathKey As String
pathKey = LCase(comp.GetPathName())
Dim alreadyDone As Boolean
alreadyDone = False
Dim k As Variant
For Each k In exportedPaths
    If k = pathKey Then alreadyDone = True: Exit For
Next k
If Not alreadyDone Then exportedPaths.Add pathKey

VBA has no native Set or Dictionary without late-binding to Scripting.Dictionary. The loop above is O(n²) for large collections — acceptable for assemblies under a few hundred parts, worth replacing with Scripting.Dictionary for larger ones.

Suppressed and Lightweight Components

Before OpenDoc6, check the component’s resolve state:

If comp.GetSuppression() = swComponentSuppression_e.swComponentSuppressed Then
    ' Skip suppressed components
End If

If comp.ResolveAllLightWeightComponents(True) <> swComponentResolveStatus_e.swResolveOk Then
    ' Handle lightweight resolve failure
End If

Suppressed components have no geometry representation in the assembly context and should be skipped entirely. Lightweight components are partially loaded — their mass/center of mass is available but the full B-rep is not. If you call OpenDoc6 on a lightweight component’s path, SolidWorks opens the full file regardless. But if the component has unresolved references when you try to export, SaveAs may write an empty or partial STEP file without raising a non-zero error code.

Calling ResolveAllLightWeightComponents before the loop ensures all components are fully resolved in the assembly context. This is a one-time call on the assembly document, not per-component.

Export Order and System Options for STEP Version

The system option for STEP version (swUserPreferenceIntegerValue_e.swSTEPExportVersion) controls the output format for every SaveAs STEP call in the session. If you need some parts in AP214 and others in AP242, set the user preference before each export:

swApp.SetUserPreferenceIntegerValue _
    swUserPreferenceIntegerValue_e.swSTEPExportVersion, _
    swSTEPExportVersion_e.swSTEP_AP214

For AP242 with PMI:

swApp.SetUserPreferenceIntegerValue _
    swUserPreferenceIntegerValue_e.swSTEPExportVersion, _
    swSTEPExportVersion_e.swSTEP_AP242
' Also enable PMI export if applicable:
swApp.SetUserPreferenceToggle _
    swUserPreferenceToggle_e.swSTEPExportAP242PMI, True

Set these before each SaveAs call in the loop, not once at the start, if your export criteria vary by component.

When to Use Which Approach

NeedUse
One STEP file for the full assembly for a supplierFile > Save As > STEP (no macro needed)
Individual STEP files per part (one file per .sldprt)Macro loop with OpenDoc6 + SaveAs
Individual DXF flat patterns per sheet metal partMacro loop (or CadShift for batch-assembly DXF)
Both STEP and DXF per part in one passMacro loop with two SaveAs calls per file
Mixed STEP versions in one batchMacro loop with system option set per export
Part-numbering and layer naming per company standardsAdd-in with pre-configured export data objects

For automating the full export pipeline — including drawing exports, PDF generation, and batch DXF alongside STEP — the automation guide covers combining these export types into a single macro run with consistent output naming.

For assemblies where you need to handle multi-body parts (where multiple flat patterns live in one .sldprt file), the multi-body DXF batch export post covers the body-selection and per-body SaveAs pattern, which differs from the per-component approach above.