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
' 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!