@pascal or @nathan can you help with this?
I am making a script to make some glass panels and I have made a definition to add a material if it doesn’t exist, and then assign it to an object. It works (but was a pain to figure out, I wish it was a simple rs.IsRenderMaterial(name) ,rs.AddRenderMaterial() option…)
But the problem is that if I undo the script then the material is still there.
And if I run the script a few times and delete the material a few times and undo a few times more after that then MORE identical materials pops up in the material list… with the same name. Isn’t that strange?
Do I have to add some stuff to make the creation of the material undoable?
Is this a bug, or are there better ways to do what I want?
def addMaterialToObject(obj_id):
render_material = False
matTable = sc.doc.RenderMaterials
for mat in matTable:
if mat.Name == "hh_GlassPanel":
render_material = mat
if not render_material:
rhino_material = Rhino.DocObjects.Material();
rhino_material.Name = "hh_GlassPanel";
rhino_material.DiffuseColor = rs.coercecolor((200,240,235))
rhino_material.Reflectivity = 0.9
rhino_material.Transparency = 0.9
print dir(rhino_material)
# Use the Rhino material to create a Render material.
render_material = Rhino.Render.RenderMaterial.CreateBasicMaterial(rhino_material, sc.doc)
sc.doc.RenderMaterials.Add(render_material)
rs.ObjectMaterialSource(obj_id, 1)
obj = sc.doc.Objects.FindId(obj_id)
obj.RenderMaterial = render_material
obj.CommitChanges();
sc.doc.Views.Redraw()
6 posts - 3 participants