Description
The SOLIDWORKS macro provided here is a means to batch export configurations to STEP.
System Requirements
- SolidWorks Version: SolidWorks 2014 or newer
- Operating System: Windows 7 or later
Pre-requisites
- You should have an assembly or part document with at least one configuration open.
- The macro should be run in the SolidWorks environment.
Results
- All configurations in the active document are saved as separate STEP files, ensuring that each design iteration is isolated from one another.
- The user determines the file name and destination by providing a unique file prefix and output directory.
- When the batch export process proceeds, status and progress are tracked via a progress bar.
Steps to Set Up the Macro
- Opening The SOLIDWORKS Document
- Prior to executing the following instructions, ensure that the Assembly or Part file containing the design configurations you wish to export is the active document in SOLIDWORKS.
- Executing the Macro
- Opening the VBA Editor: A VBA editor can be opened while SOLIDWORKS is open by pressing Alt + F11.
- Loading the Code: Add a new module using Insert > Module and paste the provided VBA code from the SOLIDWORKS macro for automated batch export in the new module window.
- Executing: You can either run the macro in the VBA Editor by selecting Run > Run Sub/UserForm, or you can save the macro as a macro file (.swp), then it can be run from the SOLIDWORKS menu (Tools > Macro > Run).
- Specify Output Parameters
After the macro has been run, you will then be prompted to input two critical parameters:
- File Prefix: Input a static string (e.g., “Project_Model_”) that will be added to the beginning of each exported file name, and help in identifying related files.
- Output Directory: Input the name of a new folder (e.g., “STEP_Exports”) that the exported files will go into.
Verify Completion
Confirm the outcome of the process:
- The progress bar will display progress in real-time, showing each configuration’s status as it is processed and saved.
- Once all configurations have been successfully converted, one last message box will appear, listing the total number of new STEP files that were saved to the path you provided.
VBA Macro Code
Visual Basic
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
' Disclaimer: ' The code provided should be used at your own risk. ' Blue Byte Systems Inc. assumes no responsibility for any issues or damages that may arise from using or modifying this code. ' For more information, visit [Blue Byte Systems Inc.](https://bluebyte.biz). Option Explicit Sub main() ' Initialize SolidWorks application and document Dim swApp As SldWorks.SldWorks Set swApp = Application.SldWorks Dim swModel As SldWorks.ModelDoc2 Set swModel = swApp.ActiveDoc ' Verify an active document is open If swModel Is Nothing Then MsgBox "No active document found. Please open a model.", vbCritical, "Error" Exit Sub End If ' Declare configuration management objects Dim swConfigMgr As SldWorks.ConfigurationManager Set swConfigMgr = swModel.ConfigurationManager Dim swConfig As SldWorks.Configuration Set swConfig = swModel.GetActiveConfiguration ' Prepare file path and name variables Dim path As String, fname As String, current As String, prefix As String, dirName As String path = swModel.GetPathName fname = Mid(path, InStrRev(path, "\") + 1, Len(path) - InStr(path, ".") - 1) path = Left(path, InStrRev(path, "\") - 1) current = swModel.GetActiveConfiguration.Name Dim configs As Variant configs = swModel.GetConfigurationNames ' User input for file prefix and output directory prefix = InputBox("Enter the prefix:", "Names", fname) If prefix = "" Then MsgBox "Prefix cannot be empty.", vbCritical, "Error" Exit Sub End If dirName = InputBox("Enter the directory name for saving:", "Directory Name", "STEP") If dirName = "" Then MsgBox "Directory name cannot be empty.", vbCritical, "Error" Exit Sub End If ' Ensure output directory exists If Dir(dirName, vbDirectory) = "" Then MkDir dirName ChDir dirName ' Progress bar setup and configuration iteration Dim i As Long For i = 0 To UBound(configs) Dim name As String name = prefix & configs(i) & ".STEP" swModel.ShowConfiguration2 configs(i) Call swModel.SaveAs3(name, 0, 0) Next i ' Confirmation message and cleanup MsgBox "Saved " & CStr(i) & " files!", vbInformation, "Done" swModel.ShowConfiguration2 current ChDir path End Sub |
Macro
You can download the macro from here
Our team of experts is at your service!
Contact us today to develop a custom solution that meets your specific workflow needs!