AddMaterialToObject

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.

Syntax

rhinoscriptsyntax.AddMaterialToObject (object_id)

rhinoscript.material.AddMaterialToObject (object_id)

Parameters

object_id

Required.  String or Guid.  The identifier of the object.

Returns

Number

The zero-based material index of the object if successful.

None

If not successful, or on error.

Example

import rhinoscriptsyntax as rs

obj = rs.GetObject()

if obj:

    index = rs.ObjectMaterialIndex(obj)

    if index==-1: index = rs.AddMaterialToObject(obj)

Also See

IsMaterialDefault

ObjectMaterialIndex

ObjectMaterialSource