SW2020 Macro / Issues in VBA Code

Hello

I can't get this macro coded under VBA to work despite all my efforts.

My goal is to change the appearance of the part based on the surface treatment I entered in the "TREATMENT" custom property. I want to create a new setup called "REALISTIC COLORS" and I want the look to have changed only in that setup.

I also can't publish my macro in the description... I exceed the 6000 characters allowed a priori... I put it in PC, if someone sees what's wrong with my code, it would be a huge help for me!!

 

Thank you!!

 


attribuer_traitement_de_surface_a_couleur.swp

Hello

The link to the file is broken

Hello 

indeed, it's very weird... I'm trying it again here!


attribuer_traitement_de_surface_a_couleur.swp

I don't think you can change the display state with SelectedFeatureProperties because the display state is not a feature.

To change the display state of the parts in an assembly look here: change_color_of_component_in_specific_display_state_example_vb

To change the color of the rooms themselves, look at this: MaterialPropertyValues

Okay, I'll try something with that then! 

Another small question, I have a hard time understanding why in their tutorial, SW they multiply the Min/Max Excel function by 16*16 and then by 16*16*16*16?

16x16 = 256, which may correspond to the color interval [0; 255], but why do this multiplication if the value of my variable is already in this format? And even more incomprehensible, why do 16x16x16x16 afterwards?? I don't understand... (I put the code snippet in question below)

 PeintureBleueRGB = Excel.WorksheetFunction.Max(Excel.WorksheetFunction.Min(PeintureBleueR, 255), 0) + Excel.WorksheetFunction.Max(Excel.WorksheetFunction.Min(PeintureBleueG, 255), 0) * 16 * 16 + Excel.WorksheetFunction.Max(Excel.WorksheetFunction.Min(PeintureBleueB, 255), 0) * 16 * 16 * 16 * 16

 

That's how RGB colors are concatenated in the Color property 

Hello again Jerome, 

I've played with your links, but I'm still running into an error that seems to come from line 189 of my code... I reused some of your code so that the appearance changes in all the parts of the set and subsets. 

It's this line of code that causes problems, but I can't find the reason : 

swApp.ActivateDoc3 swComp.Name2, False, swRebuildOnActivation_e.swRebuildActiveDoc, Empty

 

I'm putting my macro in PJ, if you could take a look at it to guide me once again, I'd be grateful!!

Thank you


attribuer_traitement_de_surface_a_couleur.swp

ActivateDoc3 requires the part name (<ModelDoc2>. GetTitle or <ModelDoc2>. GetPathName) instead of the component name (swComp.Name2)