In-Line way of including LayerMaterialIndex (etc) when creating AddLayer?

Is there an in-line way of setting LayerPrintWidth (and other attributes, like MaterialIndex, etc.) when you’re scripting for AddLayer? Example:

rs.AddLayer(new_element)
rs.AddLayer(“bbox”+new_element, Color.FromArgb(20, 0, 0, 0), parent=new_element)
rs.AddLayer(“glass”+new_element, Color.FromArgb(100, 105, 105, 105), parent=new_element)

Not in rhinoscriptsyntax, no. Here is the documentation for rhinoscriptsyntax.AddLayer(), as you can see there is no option to set the print width etc. You can change these attributes later using rhinoscriptsyntax.LayerPrintWidth for example.

Why do you need this to be in one function call?

In RhinoCommon you’d be able to change the properties of the layer being created before adding it to the document, but that will take multiple calls. Have a look at the rhinoscriptsyntax.AddLayer source code to get started with that.

Thanks for the reply @pierrec

Reason for One-Function Call: unending need to be neat and efficient. :nerd_face:

I’ll continue with the script by adding additional lines (assuming I can at least make this happen all in one script, at least.)

And thank you for the suggestion to check out RhinoCommon. I will give it a read…

I’m back on this, and been having issues.
Could u suggest how to then change the newly added layers with only names including “crv” and “bbx” have a LayerPrintWidth of -1 (nonplot)?

That would mean the kayers would be named “crv_newElement”, etc

What have you tried so far, what is the error you are seeing? rhinoscriptsyntax.LayerPrintWidth(layer, width=None) and Rhino.RhinoDocObjets.Layer.PlotWeight (get/set property) are the two ways you can change a layer’s plot weight, depending on if you are looking to use rhinoscriptsyntax or RhinoCommon.

Thx, @pierrec -

I’m using rs.
It’s the verbiage/order of ops for choosing the layer(s) I’ve just created earlier in the script, whose name(s) contain “crv” or “bbox” so I can change their PrintWidths to nonPlot (-1)

I’ve tried iterations of the verbiage suggested on Developer.Rhino3d.com for:

IsLayer
LayerId
LayerIds
As well as a couple others…

This includes the lines defining “Layer =“ and “for Layer in Layers….” Etc

And I’ve used the idea of “GetString” for a layer name like the example here, in order to choose the layers with “crv” or “bbox”:

oldname = rs.GetString(“Old layer name”)
if oldname:
newname = rs.GetString(“New layer name”)
if newname: rs.RenameLayer(oldname, newname)

I’ll post the script in a bit when I can get to my computer. Thx so much

UPDATE: Here’s my script so far…
addLayerAsTree_v03.py (1.9 KB)

rs.AddLayer returns the full name of the layer, and rs.LayerPrintWidth expects a full name for a layer as its first argument. You can save that name to a variable when creating a new layer, and then modify that layer’s properties as much as you want.

import rhinoscriptsyntax as rs
from System.Drawing import Color

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

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

Ah, that opens a whole new world, thanks so much.