This SolidWorks VBA macro automates the export of the active drawing and its referenced model to multiple file formats, while intelligently archiving previous revisions to maintain version history.
Most CAD / SolidWorks users don’t live in GitHub every day—so here are the easiest ways to grab the macro file.
Click this link to download the macro as a file (not a GitHub webpage):
If your browser opens a page instead of downloading, right‑click the link and choose Save link as….
- Click Code (green button near the top of the repo)
- Choose Download ZIP
- Unzip it, then use the macro file:
Advanced File Output with Archive.swp
- Drawing Export: Exports the current drawing to DXF (with company-wide preferences) and PDF formats.
- Model Export: Exports the referenced part or assembly to STEP format.
- Smart Filenames: Constructs filenames using custom properties (Part Number, Description, and optional Revision) from the model and drawing.
- Filename Sanitization: Automatically cleans filenames to ensure Windows compatibility by replacing invalid characters.
- Automatic Archiving: Before exporting, moves older revisions of exported files to an "Archive" subdirectory, preserving version history.
- Overwrite Protection: Checks for existing files and prompts the user before overwriting current revisions.
- Error Handling: Validates exports and reports success or failure with detailed messages.
- Creates an "Archive" folder in the same directory as the drawing if it doesn't exist.
- Archives files with older revision numbers (e.g., "Part, Desc, Rev A.dxf" if current is "Rev B").
- Also archives revision-less files that match the base name.
- Handles filename collisions in the archive by appending timestamps.
-
Prerequisites:
- SolidWorks must be installed and running.
- Open a drawing document that references a part or assembly.
- Ensure the drawing is saved to disk.
- The referenced model must have "Part Number" and "Description" custom properties set. "Revision" is optional (from the drawing).
-
Running the Macro:
- Load and run
Advanced File Output with Archive.swpin SolidWorks. - The macro will automatically archive old revisions and then export files to the same folder as the drawing.
- Load and run
-
Output Files:
<Part Number>, <Description>[, Rev <Revision>].dxf(drawing)<Part Number>, <Description>[, Rev <Revision>].pdf(drawing)<Part Number>, <Description>[, Rev <Revision>].step(model)
-
Download the macro:
- Direct download (recommended): https://github.com/kilwizac/sw-advanced-output-archive/raw/main/Advanced%20File%20Output%20with%20Archive.swp
- Or download the repository ZIP (Code → Download ZIP)
-
In SolidWorks:
- Go to Tools → Macro → Run…
- Select
Advanced File Output with Archive.swp
-
(Optional) For persistent access:
- Assign it to a toolbar button or menu.
- SolidWorks 2013 or later (due to DXF format version).
- VBA support enabled in SolidWorks.
- The macro temporarily modifies DXF export preferences but restores them afterward.
- If no referenced model is found or required properties are missing, the macro will display an error and exit.
- All exports must succeed for the macro to complete; otherwise, it stops at the first failure.
- Archived files are moved to prevent accidental loss, but can be manually restored if needed.
Feel free to fork and improve the macro. Pull requests are welcome.