This macro allows you to export the active document as a STEP file to the same directory as the original file. It will automatically name the STEP file the same as the active document, but with the .step extension. This macro is an easy way to export parts and assemblies to STEP files.
You can download an icon for the macro at this link to use when you add it as a button on a toolbar.
System Requirements
● SolidWorks Version: SolidWorks 2014 or later
● Operating System: Windows 7 or later
Pre-Conditions
● The active document must be a part or assembly.
● This macro does not work on drawing files.
● Ensure that the document is saved before running the macro, as it will export the file in the same directory.
Results
● The macro will save the active document as a .step file in the active document’s directory.
● A message box will show you where the file was saved.
VBA Macro Code
|
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 |
' 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). Dim swApp As SldWorks.SldWorks Dim Part As ModelDoc2 Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Sub main() ' Initialize SolidWorks application and active document Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc ' Exit if no document is active If Part Is Nothing Then Exit Sub ' Get the path of the active document Dim Path As String Path = Part.GetPathName ' Exit if the active document is a drawing (since STEP export is not supported for drawings) If Part.GetType = swDocDRAWING Then Exit Sub End If ' Prepare the path for the STEP file by replacing the extension Dim Extension As String Extension = Mid(Path, InStrRev(Path, ".")) Path = Replace(Path, Extension, ".step") Extension = ".step" ' Export the file as STEP longstatus = Part.SaveAs3(Path, 0, 0) ' Notify the user about the saved file location MsgBox "Saved " & Path, vbInformation End Sub |
You can download the macro from here.
Need Custom Macro Development?
Do you need changes done to the macro to accommodate your requirements or to utilize it with other processes, such as when you need to export the active document as a STEP file? At Blue Byte Systems Inc., we offer custom macro development to suit your specific needs!
