Code Library
SolidWorks APIVBASolidWorks 2016+ · built-in VBA editorMIT licenseIntermediate

Batch-export every configuration of a part to STEP (AP214)

A supplier wants every size variant of a fastener, or every finish option of a bracket, as its own neutral file — and "every configuration" of one part is a different batch problem than "every drawing in a folder." This macro walks the active document's configuration list, activates each one, and exports it to its own .step file (AP214), reporting a pass/fail count the same way the batch-PDF macro does.

Before you run it

  • A part or assembly with multiple configurations, open and active
  • SolidWorks type-library references ticked in the VBA editor
  • Edit the FOLDER and PREFIX constants before running

The code

GitHub
Option Explicit

' Batch-export every configuration of the ACTIVE part/assembly to STEP (AP214).
' Edit FOLDER and PREFIX, then run main(). Each config gets its own file:
' <PREFIX><ConfigName>.step

Const FOLDER As String = "C:\STEP\"   ' must end with a backslash
Const PREFIX As String = ""             ' optional filename prefix

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

    Dim swModel As SldWorks.ModelDoc2
    Set swModel = swApp.ActiveDoc
    If swModel Is Nothing Then
        swApp.SendMsgToUser "Open a part or assembly first."
        Exit Sub
    End If

    Dim vConfigNames As Variant
    vConfigNames = swModel.GetConfigurationNames

    Dim exported As Long, failed As Long
    Dim i As Long
    For i = 0 To UBound(vConfigNames)
        Dim configName As String
        configName = vConfigNames(i)

        ' ShowConfiguration2 makes this the active config before SaveAs
        If swModel.ShowConfiguration2(configName) Then
            Dim stepPath As String
            stepPath = FOLDER & PREFIX & configName & ".step"

            Dim errs As Long, warns As Long
            If swModel.Extension.SaveAs(stepPath, 0, 0, Nothing, errs, warns) Then
                exported = exported + 1
            Else
                failed = failed + 1
                Debug.Print "EXPORT FAILED: " & configName & " (error " & errs & ")"
            End If
        Else
            failed = failed + 1
            Debug.Print "COULD NOT ACTIVATE CONFIG: " & configName
        End If
    Next i

    swApp.SendMsgToUser exported & " STEP file(s) exported, " & failed & " failed." & _
        vbNewLine & "Failures (if any) are in the Immediate window (Ctrl+G)."
End Sub

What you get

What you get

C:\STEP\
├── Short.step
├── Medium.step
├── Long.step
└── ...

3 STEP file(s) exported, 0 failed.
Failures (if any) are in the Immediate window (Ctrl+G).

How it works

  • GetConfigurationNames returns every configuration on the document as a plain array — no tree-walking, unlike the flattened-BOM macro which has to walk components instead of configs.
  • ShowConfiguration2 is the line that matters: SaveAs always exports whatever configuration is currently active, so activating each one first is what makes this a batch instead of three copies of the same file.
  • Passing Nothing as the export-data argument to SaveAs means STEP export uses whatever AP214/AP203 and unit settings are already set in Tools → Options → Export — same as a manual Save As.
  • Exported/failed counts and Debug.Print on failure reuse the exact reporting pattern from the batch-PDF macro on purpose — once you've read one of these macros, you've read the shape of all of them.

Gotchas & honest limits

  • STEP AP214 vs AP203 and units are not set by this macro — they follow Tools → Options → Export → STEP/IGES. Set that once for your shop before batch-running.
  • ShowConfiguration2 can fail on a suppressed or error-state configuration; those are logged as failures and skipped rather than stopping the batch.
  • This exports configurations of one open document — to batch many different files' configs, wrap this in the same Dir$ folder loop the batch-PDF macro uses.
  • Assemblies: exporting a configuration exports that configuration's resolved state, including whatever suppression state its components are in — check one output file before trusting the whole run.

Goes deeper

Want this adapted to your shop — or built into a real tool?

Samples are the free 80%. The last 20% is the part I do for a living.

Get in touch
Home
Blog
Tools
Code
Email
LinkedIn
Résumé