Is it possible in python to open an .rmtl file and apply it to a layer? And, if so, how?
Hi @williamjb741, below seems to do it:
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def DoSomething():
rmtl_file = rs.OpenFileName("Open", "RMTL Files (*.rmtl)|*.rmtl||")
if not rmtl_file: return
layer_path = rs.GetLayer("Layer to apply material to", None, False)
if not layer_path: return
material = Rhino.Render.RenderContent.LoadFromFile(rmtl_file)
layer_index = scriptcontext.doc.Layers.FindByFullPath(layer_path, -1)
layer = scriptcontext.doc.Layers[layer_index]
layer.RenderMaterial = material
DoSomething()
_
c.
1 Like
I didn’t want the dialogs. So this is what I came up with based on your answer. And it worked. It was that Rhino.Render.RenderContent.LoadFromFile that I really needed. Thanks a million!
import Rhino
import scriptcontext as sc
layer_index = sc.doc.Layers.FindByFullPath("LayerName", Rhino.RhinoMath.UnsetIntIndex)
layer = sc.doc.Layers[layer_index]
material_path = "..\\PathRelativeToThisScript\\MyCoolMaterial.rmtl"
material = Rhino.Render.RenderContent.LoadFromFile(material_path)
layer.RenderMaterial = material