Assign Material to Layer

HI,

I’m trying to loop through a GH tree and bake each branch to a layer in Rhino with a particular colour and material. The materials are already created in Rhino but aren’t used yet, so are accessible via sc.doc.RenderMaterials. I;m struggling now though to assign one of these materials to a Rhino layer. I;ve tried using rs.LayerMaterialIndex(Name,MatIndex) but I cant seem to access the material’s index

Any help much appreciated! Code snippet below.

for Objs,Name,Material,Colour in zip(RhinoObjs,Names,Materials,Colours):
    if Name not in LayerNames:
        Colour = System.Drawing.Color.FromName(Colour)
        rs.AddLayer(Name,Colour)
        MatIndex = [mat for mat in MaterialTable if mat.Name == Material]
        rs.LayerMaterialIndex(Name,MatIndex)
    layer = sc.doc.Layers.FindName(Name)
    sc.doc.Layers.SetCurrentLayerIndex(layer.Index,True)
    [sc.doc.Objects.Add(obj) for obj in Objs]
1 Like

similar question i had here

hoping that the api will opens up assignment to the Materials table from the RenderMaterials table

1 Like