How to assign Material to objects Without User input

Okay, so I am aware of rs.ObjectMaterialIndex to change a object’s material index, but I am in a tussle trying to figure out how to do a simple material assignment to an object. Think of this as simulating a _visApplyMaterial or Apply Material to Object BUT without prompting the user for any input whatsoever. Here’s what I have so far:

Plane = rs.AddPlaneSurface( rs.WorldXYPlane(), 5.0, 5.0 )
rs.SelectObject (Plane)
rs.ObjectMaterialSource (Plane,1)
#rs.ObjectMaterialIndex ("not too sure what to do with this!")

I want to apply the material called White Reflective (ID: 7a1ea260-ded9-4cec-9216-f070a11d4720) to the plane.

Related: if someone can lead me to a discussion or code that helps me understand how to script selection of specific objects or layers (without user input), that would be great! Thanks.

P.S. To give some context, here’s what I’m looking to do: I want to somehow be able to select the ground plane (by obtaining it’s object ID) in the model, and then assign a material to it.

Does rs.AddMaterialToObject help?


I’ve been trying to understand the documentation for AddMaterialToObject and the example code:

import rhinoscriptsyntax as rs
obj = rs.GetObject()
if obj:
    index = rs.ObjectMaterialIndex(obj)
    if index==-1: index = rs.AddMaterialToObject(obj) 

From what I understand, using a combination of ObjectMaterialIndex and AddMaterialToObject, I can find out what material is applied to say object1 and then apply that material to object2. But that doesn’t seem very helpful if I want to apply a material say ‘White Matte’ to a object which has not been applied to any other object yet.