Change Material per Layer to per Object

Hi,

I was wondering if this was possible native of if there is a script out there that I have missed.

Basically I want to assign material to objects to be per-obeject instead of per-layer, assigning the material of the layer to all objects inside that layer.

Thanks

Hello- this should do it

import rhinoscriptsyntax  as rs
def PerObjectMat():
    layers = rs.GetLayers()
    if not layers: return
    miss = False
    for layer in layers:
        idx = rs.LayerMaterialIndex(layer)
        ids = rs.ObjectsByLayer(layer)
        if not ids:
            miss = True
            continue
        
        for id in ids:
            if rs.ObjectMaterialSource(id) == 0:
                rs.ObjectMaterialSource(id,1)
                rs.ObjectMaterialIndex(id, idx)
    if miss:
        print("No objects found on some layers")
if __name__ == '__main__':
    PerObjectMat()

-Pascal

1 Like

Hi Pascal, thanks.

Is this working for all selected objects or layers? Because when I ran the script I get a menu to select layers and I can only select one at a time

@ShynnSup try now…

-Pascal

1 Like

Works perfectly, thank you!