I’m using this script as a macro in Rhino. It raises an error when there’s no material in the material table. Other than that it works fine.
You get to choose the material name in a popup:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import re
ids = rs.GetObjects("Select objects to change material", preselect=True)
rmats = [rm for rm in sc.doc.RenderMaterials]
materialNames = []
for mat in rmats:
if not bool(re.search(r"\s", mat.Name)) and len(mat.Name) <= 10:
materialNames.append(mat.Name)
materialNames.sort()
result = rs.ListBox(materialNames, "", "Materials")
rs.SelectObjects(ids)
cmdString_n = "-_RenderAssignMaterialToObjects " + result + " " "n"
rs.Command(cmdString_n, True)
cmdString_y = "-_RenderAssignMaterialToObjects " + result + " " "y"
rs.Command(cmdString_y, True)
rs.UnselectAllObjects()
Hi, managed to post on a colleagues account This does what im after very nicely! How do link this script to a button? I tried to past it in the command section of the button editor but had no luck. Completely fresh when it comes to scripting.