'None Type' object has no attribute 'MaterialSource'

Hey all,

I keep getting the warning " ‘None Type’ object has no attribute ‘MaterialSource’ ". I swear this was working hours ago when at work (I have OneDrive syncing files between work and home), but now I keep getting this error. I am feeding guids into the node, and do not understand why it’s returning the error.

For context, I’m trying to return a list of materials assigned to objects, regardless of whether each object’s material source is from it’s layer, or from the object itself.

Any help is greatly appreciated!

Get Object Material.gh (3.7 KB)


I got rid of the error by using rhinoscriptsyntax.ObjectsByType to get a reference to a polyline I placed in Rhino. But there was no data on there to test that it does anything. The error messages were more useful if you connect the geom to objs directly (without the ID Param in there) and set the type hint to none or geometry - to let GhPython’s auto-magic do its thing.

It feels like an issue of GH geometry, GH references to Rhino objects, and actual Rhino guids to me.

sc.doc = Rhino.RhinoDoc.ActiveDoc

p_lines = rs.ObjectsByType(4)

    a = get_materials(p_lines)
    sc.doc = ghdoc


Thanks for the response. Referencing script context and pointing to the active Rhino doc did the trick. I was reading on other forum posts that GH geometry does not have many of the same attributes as the referenced Rhino geometry. See the final script below. I also posted gh file for those that may find it useful. I probably don’t need the “import Rhino” line, but just left alone.

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

sc.doc = Rhino.RhinoDoc.ActiveDoc

def get_materials(objects):
    materials = []
    for obj in objects:
        material_source = rs.ObjectMaterialSource(obj)
        if material_source == 0:
            layer = rs.ObjectLayer(obj)
            layer_material_index = rs.LayerMaterialIndex(layer)
            #layer_material_name = rs.MaterialName(layer_material_index)
        elif material_source != 0:
            material_index = rs.ObjectMaterialIndex(obj)
            #material_name = rs.MaterialName(material_index)
    return materials
    a = get_materials(objs)

    sc.doc = ghdoc

Get Object Materials - Final.gh (3.6 KB)

1 Like