Adds a material to an object and returns the new material's index. Note, adding a material to an object modifies the object's material source from "By Layer" to "By Object." See ObjectMaterialSource for details. If the object already has a material, then the object's current material index is returned.
rhinoscriptsyntax.AddMaterialToObject (object_id)
rhinoscript.material.AddMaterialToObject (object_id)
object_id |
Required. String or Guid. The identifier of the object. |
Number |
The zero-based material index of the object if successful. |
None |
If not successful, or on error. |
import rhinoscriptsyntax as rs
obj = rs.GetObject()
if obj:
index = rs.ObjectMaterialIndex(obj)
if index==-1: index = rs.AddMaterialToObject(obj)