I often get step-files. The coordinate system will never be the same. So I searched for solutions, that transform the main coordinate system into another. I found a good solution here on Stack Overflow
system Sub SaveToStep() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swModelActivated As SldWorks.ModelDoc2 Dim swModelToExport As SldWorks.ModelDoc2 Dim strModelName As String Dim nStatus As Long Dim nErrors As Long Dim nWarnings As Long 'Declare variables Dim OutputCoordSys As String Dim FileToExport As String Dim StepFile As String Set swApp = Application.SldWorks FileToExport = "C:Usersmypathmypart.SLDPRT" OutputCoordSys = "Koordinatensystem1" StepFile = Replace(FileToExport, ".SLDPRT", ".STEP") 'Open Set swModel = swApp.OpenDoc6(FileToExport, 1, 0, "", nStatus, nWarnings) 'Activate the model strModelName = swModel.GetTitle Set swModelActivated = swApp.ActivateDoc3(strModelName, False, swRebuildOnActivation_e.swUserDecision, nErrors) 'Get the active model Set swModelToExport = swApp.ActiveDoc 'Assign correct STEP swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swStepAP, 214 'Set Export appearences option to true swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swStepExportAppearances, True 'Assign Output coordinate system to use swApp.SetUserPreferenceStringValue swUserPreferenceStringValue_e.swExportOutputCoordinateSystem, OutputCoordSys 'Save the file as step swModelToExport.Extension.SaveAs3 StepFile, 0, 1, Nothing, Nothing, nErrors, nWarnings End Sub
I tried the code. The preferences will be changed correctly. I checked it by stopping before SaveAs3 in the program code and looking in the settings. But when I open the Step-File, the position of coordinate system is the old position.
When I save manually, the right (new) coordinate system is used in step-file.
Has someone an idea how I can solve this problem?
user28659248 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.