I'd like to get all materials using an ambient occlusion (AO) node and return their names in the console:
import bpy mat = bpy.data.materials for mat in mat: mat_name = (mat.name) ntree = mat.node_tree node = ntree.nodes.get("Ambient Occlusion", None) if node is not None: print("Material With Ambient Occlusion:", mat_name)
It works fine for the start up file, but when I run it in another scene I get this error:
AttributeError: 'NoneType' object has no attribute 'nodes'
What is wrong? And why does the code only work for the start up file?