I have a macro that saves as .step to a spesified folder, somtimes the files get corrupted (no data in file or the faces are all messed up). When the solidworks has started to make corrupt files it will do so with the macro and if do it manually. Thenn i have to reset .step export options (save as> export options> reset> reset this page only). Then i recheck the all the same boxes i had and press ok. Now it works again.
I have similar problems when importing .step files, sometimes the faces are all messed up, reset options works here as well.
My question is this, can i add something to my macro to reset export options? Many thanks
Attached corrupt .step file and error log.
Sample of my code below:
Sub ExportStep()
Dim swApp As SldWorks.SldWorks
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
Dim swFeat As SldWorks.Feature
Set swFeat = swModel.FirstFeature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
Dim SaveAsName As String
SaveAsName = swCustPropMgr.Get("PartNo")
Dim SavePath As String
SavePath = "C:\temp\"
If SaveAsName = "" Then
MsgBox swModel.GetTitle & " Prop missing will save as file name!"
If TypeOf swModel Is PartDoc Then
SaveAsName = Replace(swModel.GetTitle, ".SLDPRT", "", , , vbTextCompare)
ElseIf TypeOf swModel Is AssemblyDoc Then
SaveAsName = Replace(swModel.GetTitle, ".SLDASM", "", , , vbTextCompare)
End If
End If
Debug.Print SaveAsName
Dim RetVal As Boolean
Dim errors As Long, warnings As Long
'change the step file options
RetVal = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swStepAP, 214)
'save
swModel.SaveAs2 SavePath & SaveAsName & ".step", 0, True, False
End Sub