Data path for driver: secret of 'node_tree.' 1) I prepared two objects for driving.


2) I copied the data path of the color property of diffuse shader in Suzanne's material node to drive the box.
nodes["Diffuse BSDF"].inputs[0].default_value : failure


3) This time, I found the Data Api in the outliner, do copy data path, and created an index at the end of the path.
nodes["Diffuse BSDF"].inputs[0].default_value[0] : failure


4) This time I copied the property values that are displayed in the info window.
bpy.data.node_groups["Shader Nodetree"].nodes["Diffuse BSDF"].inputs[0].default_value[0] : failure


5) I found a solution to use the node_tree. prefix via googling.
node_tree.nodes["Diffuse BSDF"].inputs[0].default_value[0] : Eventually succeed
node_tree.nodes["Diffuse BSDF"].inputs[0].default_value[1] : succeed
node_tree.nodes["Diffuse BSDF"].inputs[0].default_value[2] : succeed
node_tree.nodes["Diffuse BSDF"].inputs[0].default_value[3] : succeed
node_tree.nodes["Diffuse BSDF"].inputs[0].default_value.r : succeed
node_tree.nodes["Diffuse BSDF"].inputs[0].default_value.g : succeed
node_tree.nodes["Diffuse BSDF"].inputs[0].default_value.b : succeed
node_tree.nodes["Diffuse BSDF"].inputs[0].default_value.a : succeed
But I can't figure out what node_tree. Is and where it comes from.


6) I want to figure out exactly the rules for dealing with data paths.


Thank you in advance.
When creating a driver with the property set to material, you're implicitly using a reference to an object of type bpy.types.Material.

Your first attempts in step 2) and 3) didn't work because bpy.types.Material has no attribute called node. The idea in step 4) has the same problem as the previous attempts, because the driver tries to access these attributes in the material object of type bpy.types.Material and since there is no bpy.types.Material.bpy this fails as well.

The correct way to access the nodes is indeed through node_tree since that is an attribute in the object of type bpy.types.Material. It gives you access to all nodes in the referenced material.

Attempt 6) fails again because there is no shader_nodetree in bpy.types.Material.node_tree.

For questions like these you can always consult Blender's Python API docs.