I just learned the below:

tl = bpy.context.scene.node_tree.links

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'links'

enter image description here

  • $\begingroup$ bpy.context.scene.node_tree refers to the compositor node_tree. If there's no compositor setup, then there's no node_tree and therefore node_tree.links doesn't exist. If you want the material node_tree you should use bpy.data.materials['yourmaterial'].node_tree. $\endgroup$
    – Secrop
    Jan 26, 2019 at 15:27
  • $\begingroup$ @Secrop suspect it's a follow on from blender.stackexchange.com/questions/129948/… $\endgroup$
    – batFINGER
    Jan 26, 2019 at 15:40
  • $\begingroup$ @batFINGER, yeah, an unfamiliarity with the api. $\endgroup$
    – Secrop
    Jan 26, 2019 at 22:06
  • $\begingroup$ sorry, I want to know how to link the Surface to BSDF or Color to Base Color in the picture by python script $\endgroup$
    – jow
    Jan 27, 2019 at 11:08


Browse other questions tagged .