Hello everyone,
I created a macro that automatically generates room configurations corresponding to paint RALs.
In solidworks, I created the materials corresponding to the RAL by putting the right associated appearances on them.
In a room, when I manually apply and change the material, the colors vary well in correspondence.
With macro, the configurations are well created, the materials are well applied and the appearances correspond well to the configurations.
But the colors of all the configurations are all like that of the first configuration, therefore of the first appearance
When I edit the material and click apply without changing anything, the appearance corrects itself and changes to the right color.
Do you have any idea of the problem?
Below is the code:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConfig As SldWorks.Configuration
Dim vConfigName As Variant
Dim sSpecConfigNameArr(0) As String
Dim vSpecConfigNameArr As Variant
Dim dimValue As Variant
Dim stnameConfig As String
Dim boolstatus As Boolean
Dim i As Integer
Dim swErrors As Long
Dim swWarnings As Long
Dim swPart As SldWorks.PartDoc
Dim tConfig() As String
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim sMasse As String
Dim sValout As String
Dim sVal As String
Sub main()
'''-----------------------------------------------
Set swApp = Application.SldWorks
'on récupére le document actif
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
'on récupére la configuration active
Set swConfig = swConfigMgr.ActiveConfiguration
stnameConfig = swConfig.Name
vConfigNameArr = swModel.GetConfigurationNames
Set swModelDocExt = swModel.Extension
'''-----------------------------------------------
'on boucle sur toutes les configurations
For Each vConfigName In vConfigNameArr
'on test si la configuration est différente de la configuration active et de la configuration Default
If vConfigName <> swConfig.Name And vConfigName <> "xx" Then
boolstatus = swModel.DeleteConfiguration2(vConfigName)
End If
If vConfigName <> swConfig.Name And vConfigName <> "Défaut" Then
boolstatus = swModel.DeleteConfiguration2(vConfigName)
End If
Next vConfigName
'on reconstruit la pièces
swModel.ForceRebuild3 False
Do
'récupère le document actif dans SW
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
''' lignes déplacées dans la boucle, de manière à ce que l'operation s'effectue sur tous les fichiers et pas juste le premier.
Set swPart = swModel
'=> Création de la configuration ALUMINIUM Brut (non peint)
boolstatus = swPart.AddConfiguration2("00", "", "", True, False, False, True, 256)
boolstatus = swModel.DeleteConfiguration2("Défaut")
boolstatus = swModel.DeleteConfiguration2("xx")
boolstatus = swModel.DeleteConfiguration2("PC")
'''-----------------------------------------------
'Mise en place de la matière
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060"
'=> Création des configuration ALUMINIUM Peint (RAL)
boolstatus = swPart.AddConfiguration2("R1013", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 1013"
boolstatus = swPart.AddConfiguration2("R1018", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 1018"
boolstatus = swPart.AddConfiguration2("R2008", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 2008"
boolstatus = swPart.AddConfiguration2("R3000", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 3000"
boolstatus = swPart.AddConfiguration2("R3004", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 3004"
boolstatus = swPart.AddConfiguration2("R5015", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 5015"
boolstatus = swPart.AddConfiguration2("R6005", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 6005"
boolstatus = swPart.AddConfiguration2("R6018", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 6018"
boolstatus = swPart.AddConfiguration2("R6029", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 6029"
boolstatus = swPart.AddConfiguration2("R7016", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 7016"
boolstatus = swPart.AddConfiguration2("R7035", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 7035"
boolstatus = swPart.AddConfiguration2("R7037", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 7037"
boolstatus = swPart.AddConfiguration2("R9005", "", "", True, False, False, True, 256)
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060 - RAL 9005"
'''----------------------------------------------------------------------------
'Enregistre le docuement actif en mode silencieux
bRet = swModel.Save3(swSaveAsOptions_Silent, swErrors, swWarnings)
'Ferme le document actif
swApp.CloseDoc swModel.GetPathName
End If
'boucle jusqu'a ce qu'il n'y ai plus de fichier ouvert dans SW
Loop While Not swModel Is Nothing
End Sub