Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4171

Assigning RenderMaterial to Layers with a Python script

$
0
0

Hello,
**I am trying to edit the RenderMaterial property of the Layer Class, to automate the creation of layers with a preset material, color, linetype, etc. **

**I got Layer.Color to work but for some reason I can’t really understand Layer.RenderMaterial() seems to not work.

Not sure what is happening under the hood or where my code is not working. Happy to hear some advices.**

doc = Rhino.RhinoDoc.ActiveDoc

render_mat= Rhino.Render.RenderMaterial.CreateBasicMaterial(Rhino.DocObjects.Material())
render_mat.Name="Wood"

existing_mat = [mat.Name for mat in doc.RenderMaterials]

if render_mat.Name not in existing_mat:
    doc.RenderMaterials.Add(render_mat)

def create_layer(df):

    existing_layer = [layer.Name for layer in doc.Layers if layer.IsDeleted == False]

    for i in df:
        if i[1]['LAYER_NAME'] not in existing_layer:

            newlayer=Rhino.DocObjects.Layer()
            newlayer.Name=i[1]['LAYER_NAME']
            newlayer.Id=System.Guid.NewGuid()
            newlayer.RenderMaterial=render_mat

            print(newlayer.RenderMaterial)

            try:
                newlayer.Color= i[1]['RHINO_PEN']
            except:
                newlayer.Color= rs.CreateColor(255, 0, 0)

            doc.Layers.Add(newlayer)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4171

Latest Images

Trending Articles



Latest Images