Hi all
I'm having a problem exporting SolidWorks models to STEP files. When I use the manual method to export a STEP file, the appearances applied to the part (colors, textures, etc.) are correctly preserved in the file. However, when I try to automate this process using a VBA macro, the appearances are not exported, even though everything seems to work fine in terms of saving the file.
Here's what I've already tried:
- Manual export : When I choose " Export to STEP " manually, I select the STEP AP214 format, which allows me to keep the appearance.
- Export via VBA macro : Using the method
.SaveAs
in the macro, the STEP file is saved, but without appearances.
I checked the export options, and the " Export Appearances " option is enabled in SolidWorks. The file is exported in STEP AP203 by default, and I think this could be the reason why appearances are not kept.
I've tried several approaches to force the export in AP214 STEP and enable the necessary options via the macro, but I'm experiencing compilation errors and compatibility issues with the export methods.
Here is the extract of my macro which really does a lot of other things but here I put you the export part of the step
thank you in advance
Function SaveModelAsSTEP(swModel As ModelDoc2, saveFolderPath As String, value As String, indexValue As String) As String
Dim stepFileName As String
Dim fullSTEPPath As String
Dim status As Boolean
Dim response As VbMsgBoxResult
' Vérifier si le modèle est un assemblage
If swModel.GetType() = swDocASSEMBLY Then
' Demander à l'utilisateur s'il souhaite enregistrer le fichier STEP
response = MsgBox("Il s'agit d'un assemblage. Voulez-vous enregistrer le fichier STEP ?", vbYesNo + vbQuestion, "Enregistrement STEP")
' Si l'utilisateur choisit non, sortir de la fonction sans enregistrer
If response = vbNo Then
SaveModelAsSTEP = ""
Exit Function
End If
End If
' Formater le nom du fichier STEP
stepFileName = UCase(Trim(value)) & "-" & Trim(indexValue) & ".STEP"
fullSTEPPath = saveFolderPath & stepFileName
' Vérifier si le fichier STEP existe déjà
If Dir(fullSTEPPath) <> "" Then
response = MsgBox("Le fichier STEP '" & stepFileName & "' existe déjà." & vbCrLf & _
"Voulez-vous l'écraser ?", vbYesNo + vbQuestion, "Fichier existant")
If response = vbNo Then
SaveModelAsSTEP = ""
Exit Function
End If
End If
' Enregistrer le modèle en tant que fichier STEP
status = swModel.SaveAs(fullSTEPPath)
' Retourner le chemin du fichier STEP si l'enregistrement est réussi
If status Then
SaveModelAsSTEP = fullSTEPPath
Else
SaveModelAsSTEP = ""
MsgBox "Erreur lors de l'enregistrement du fichier STEP.", vbExclamation
End If
End Function