2
$\begingroup$

1) I prepared two objects for driving. enter image description here

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 enter image description here

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 enter image description here

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 enter image description here

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. enter image description here

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

Thank you in advance.

$\endgroup$
0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Oh, I think I know a bit. I'll ask you a little bit more. After that, I copied the transform data path into a driver single property. location [0] It worked fine but I was puzzled. The material attribute required a prefix of node_tree, but the transform attribute works without any prefix. What's the difference between the two? $\endgroup$ – J. SungHoon Sep 15 '19 at 19:26
  • $\begingroup$ @J.SungHoon Just to be sure I'm understanding you right. You have a variable that is a Single Property, the Prop is set to an object and Path is set to location[0]? That works because you're using an object as property (bpy.types.Object) which has a location attribute. See: docs.blender.org/api/current/… $\endgroup$ – Robert Gützkow Sep 15 '19 at 19:43
  • $\begingroup$ It gave me a lot of hints. I haven't learned Python specifically yet so I can't easily navigate the documentation you link to, but after learning Python I came back to see your answer again. Thank you. $\endgroup$ – J. SungHoon Sep 16 '19 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.