Macro export step with coordinate system and appearances

Hello

I have a macro to export my files in step and include the index and the export date in the file name.
Now I would like to add a point about the coordinate system. I would like the output coordinate system to be the " Coordinate System1 " and not the default one at the time of export, unless it does not exist.
I would also like to keep the appearances (colors).

Below is my macro:

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swModelDocExt = Part.Extension

If Part Is Nothing Then End

' Retrieve revision index
Set swCustProp = swModelDocExt.CustomPropertyManager("  ")
bool = swCustProp.Get4(" Review ", False, val, valout)

File Saving Status
DateiMitPfad = Part.GetPathName()
If DateiMitPfad = "  " Then
MsgBox (" Please save the file before this macro runs! ")
Part.Save
End If

' We retrieve the current date and put it in a format that can be put in the name of a file
Dim dateNow As String
dateNow = Replace(Date, " / ", " . ")

sFilePath = Left(Part.GetPathName, InStrRev(Part.GetPathName, ""))

FileName = Mid(Part.GetPathName, InStrRev(Part.GetPathName, "") + 1)
FileName = Left(FileName, InStrRev(FileName, " . ") - 1)
FileName = sFilePath & "" & FileName

Part.SaveAs2 FileName + " - " & valout & " - " & dateNow & ".  STEP ", 0, True, False

End Sub

Thank you very much
Manu

As for appearances, I think I've found the solution.

Your macro needs to modify the Step export options to change the coordinate system:
https://help.solidworks.com/2024/english/api/swconst/FileSaveAsSTEPOptions.htm
See the Output coordinate system section

In C# you have to add this before saving:

bool boolstatus = false;
boolstatus = swApp.SetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swExportOutputCoordinateSystem, "Système de coordonnées1");
2 Likes