Assign Material to Layer


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)
        MatIndex = [mat for mat in MaterialTable if mat.Name == Material]
    layer = sc.doc.Layers.FindName(Name)
    [sc.doc.Objects.Add(obj) for obj in Objs]

similar question i had here

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