Assign material with a macro

I am trying to make a macro to assign a premade material to objects. I found this old thread from rhino 6 but cant get it to work?

So work flow is to click on the macro button, i then selected the objects, when i hit enter it assigns the material already created called “Completed”

Hi @stigolsson

This should work as long as you have a material called Completed

-Materials Options AssignToObjects Completed Pause Enter Enter

HTH, Jakob

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("\s", mat.Name)) and len(mat.Name) <= 10:

result = rs.ListBox(materialNames, "", "Materials")

cmdString_n = "-_RenderAssignMaterialToObjects " + result + " " "n"
rs.Command(cmdString_n, True)
cmdString_y = "-_RenderAssignMaterialToObjects " + result + " " "y"
rs.Command(cmdString_y, True)


Hi, managed to post on a colleagues account :joy: 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.

Rhino - Running Scripts from Macros (

Integrating macros and scripts into your workspace [McNeel Wiki]

Save the script above as a python script and you’ll see in the links above how to setup the button…