Edit Dec 7 2018,
Credit for the original macro that I modified in the below thread goes to Artem Taturevych in the below thread:
https://forum.solidworks.com/message/420553#comment-420553
---------------------------------------------------------------
Running SW 2017
I was excited to get a macro working (a first for me, I'm quote new) until I realized that it wasn't quite doing what I intended for .step (but it worked for .igs). Sigh...
A frustrating issue I've had to deal with is making .step files from assemblies. The issue is that when you save from .sldasm files straight to .step format the resulting assembly does not keep the mechanical mates. Now the mates remain if the steps go as follows:
- save .sldasm to .sldprt
- open .sldprt
- resave as .step
It's been insisted that the mates remain and I was excited at first because the below macro did lock the mates for .igs (which I recall had a similar issue).
I have tried #Task but this is having it's own issues to the Standard License, posted on a separate thread:
First, is there a simple option for .step export that locks parts upon opening (like for Parasolid, .x_t)? I've been unable to find anything in SW or the forums. If not, then
below is the macro at the moment:
---------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim fileerror As Long
Dim filewarning As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Dim path As String
path = swModel.GetPathName
If path <> "" Then
Dim filename As String
filename = InputBox("Enter the CAD String")
SaveFile filename & ".sldprt"
SaveFile filename & ".x_t"
SaveFile filename & ".easm"
'Second Sub is to Lock Assembly Components into Place by opening the resaving the .sldprt file'
Dim filename2 As String
filename2 = filename & ".sldprt"
SaveFile2 filename & ".step"
End If
End If
End Sub
Sub SaveFile(filename As String)
swModel.SaveAs4 filename, _
swSaveAsVersion_e.swSaveAsCurrentVersion, _
swSaveAsOptions_e.swSaveAsOptions_Copy, 0, 0
End Sub
Sub SaveFile2(filename As String)
Set swModel = swApp.OpenDoc6(PathEnd + filename2, swDocPART, swOpenDocOptions_Silent, "", fileerror, filewarning)
Set swModel = swApp.ActiveDoc
swModel.SaveAs4 filename, _
swSaveAsVersion_e.swSaveAsCurrentVersion, _
swSaveAsOptions_e.swSaveAsOptions_Copy, 0, 0
End Sub
---------------------------------------------------------------
The macro does properly export .step files (no errors appear) but it appears to be saving the files from the assembly and not the opened part (as the OpenDoc6 line in SaveFile2 is intended to do). How do I get the Macro to properly open the .sldprt file and resave it as a .step?
Many thanks in advance,
Joseph
SolidworksApi/macros