Change colour of certain component of assembly

I need to change colour of a product that is on top of WorkPieceCarrier (assembly) when assembly reaches a sensor. I want to change the colour of the product only. I used the code below:
triggerCondition(lambda: getTrigger() == boolSignal and boolSignal.Value)
part = compSignal.Value
red = app.findMaterial(“red”)
delay (5)
part.NodeMaterial = red
part.MaterialInheritance = VC_MATERIAL_FORCE_INHERIT
I tried using this method at sensor. Sadly this grabs the whole assembly as the part and changes colour of WPC as well. Is it possible to achieve this color change for certain component of assembly in sensor?

The part is a child (or grandchild) component of the assembly. You can try something like this:

assembly = compSignal.Value
part = assembly.ChildComponents[0]

Note that the part is likely not the first child, so you need to iterate over all child components and the children of the child components to find the correct part.

1 Like