ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
JGJohn Girgenti20/03/2012

Hello,

I have bee trying change the Material Properties of the componets within an assembly but at the assembly level (part-instance@assembly) and have so far failed. I have been able to successfully change the properties at the part level through the assembly by selecting the parts and then using the assembly ModelDoc2.MaterialPropertyValues. If I select the parts by name, using the partname-instance "@" assemlby name convention nothing happens.  I can change the top level color for the assembly using the ModelDoc Extension.SetMaterialPropertyValues for the assemly.

Code for changing assemlby top level Material Properties

IModelDoc2 modDoc = default(IModelDoc2);


// Get the current document

modDoc = (IModelDoc2)iSwApp.ActiveDoc;   

// Create a null object for SetMaterialPropertyValues

object oNull = new object();

// Set properties array [ R, G, B, Amb, Dif, Spec, Shine, Trans, Emis ]

Double[] properties = { 1, .5, .25, 0.5, 0.5, 0, 0, 0, 0 };

// Set the properties

modDoc.Extension.SetMaterialPropertyValues(properties, (int)swInConfigurationOpts_e.swThisConfiguration, oNull);

...end code

Code for changing part level Material Properties within an assembly

IModelDoc2 modDoc = default(IModelDoc2);               

IComponent2 swComp = default(IComponent2);

IModelDoc2 compDoc = default(IModelDoc2);


// Get the current document

modDoc = (IModelDoc2)iSwApp.ActiveDoc;                                           

// I'm just testing with one preselected part here

// Note: preselection gets the part level, not assembly component level

int count = modDoc.SelectionManager.GetSelectedObjectCount2(-1);

if (count == 1)

{

     // Get the component of the selection

     swComp = modDoc.SelectionManager.GetSelectedObjectsComponent3(1, -1);     

     // Get the modeldoc of the component

     compDoc = swComp.GetModelDoc2();                                          

     // Set properties array [ R, G, B, Amb, Dif, Spec, Shine, Trans, Emis ]

     Double[] properties = { 1, .5, .25, 0.5, 0.5, 0, 0, 0, 0 };


     compDoc.MaterialPropertyValues = properties;

}

...end code

I think I may have been looking at this too long. Does anyone know how to accomplish this?

Thanks in advance!