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

Assign Existing Custom Material to Layer(s) within a script

$
0
0

I’m trying to assign existing (non-default) materials (by name or index) after the AddLayer portion of my script.

Seems like it should be very simple, but I’ve tried my darndest to figure this out, including all the script-bits that seem like they should do it, including AddMaterialToLayer; and LayerMaterialIndex (which states: Returns or changes the material index of a layer, but I can’t figure out how to enact the “change” ability.) I also looked into LayerId, etc.

Searched this forum, Developer site, sample scripts, and GitHub, which had a breakdown of the Material scripts, yet no mention of how to actually assign an existing material.

Here’s my script so far, which creates a set of subLayers beneath a Layer, and assigns properties to them. (Ultimately I’m planning on having options for selected/different/additional subLayers.)

# Creates a specified template layer tree for a new element
# v04 by Alan Farkas 230327

import rhinoscriptsyntax as rs
from System.Drawing import Color
#from System.Drawing import Color

new_element = rs.GetString("New Element?")
new_element = new_element[0].upper()+new_element[1:]

rs.AddLayer(new_element)
rs.AddLayer("crv"+new_element, Color.Red, parent=new_element)
rs.AddLayer("bbox"+new_element, Color.FromArgb(20, 0, 0, 0), parent=new_element)
rs.AddLayer("light"+new_element, Color.Aqua, parent=new_element)
rs.AddLayer("glass"+new_element, Color.FromArgb(100, 105, 105, 105), parent=new_element)
rs.AddLayer("sol"+new_element, Color.Green, parent=new_element)
rs.AddLayer("ref"+new_element, Color.Black, parent=new_element)
rs.AddLayer("SM_"+new_element, Color.White, parent=new_element)

layers = rs.LayerNames(new_element)
if layers:
    for layer in layers:
        black = rs.CreateColor((0,0,0))
        if rs.LayerPrintColor(layer)!=black:
            rs.LayerPrintColor(layer, black)

#Set LayerPrintWidths
#This works in v3A

bbox_layer_name = rs.AddLayer("bbox"+new_element, Color.FromArgb(20, 0, 0, 0), parent=new_element)
rs.LayerPrintWidth(bbox_layer_name, -1)

crv_layer_name = rs.AddLayer("crv"+new_element, Color.Red, parent=new_element)
rs.LayerPrintWidth(crv_layer_name, -1)

#Assign Existing Custom Materials to the appropriate above subLayers


7 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles