There is an mesh with an animated shape key. How can I access/reuse the value of this shape key in a driver for a emission material? (How to add a driver to a shader value is known...the way to access the value of the shape key is the problem for me here.)
Enable Python Tooltips in Preferences > Interface > Display. This helps discovering the data paths. To check if a path is correct, paste it into the >>> prompt in the Scripting workspace and hit enter. Either you'll see its value printed out, or it'll give an error message that the path was wrong.
With that, I was able to work out this:
- Select your object with the keyframed shape key.
- In its object data under Shape Keys, right-click the keyed value and select 'Copy Data Path' (or Shift-Ctrl-C). For me this yielded
key_blocks["Key 1"].value, since "Key 1" was the only shape key I had other than the Basis shape. I noticed that the Python tooltip was actually longer, and said:
Which tells us everything we need to use this in a driver.
In the Shader workspace add a new Input > Value Node. Right click on the numerical value field of that node, and 'Open Drivers Editor' or just Add Driver and try editing in the smaller window.
Set the 'var' input variable to be a 'Single Property'.
- On the 'prop:' row set the ID Type (the small icon part) to "Key".
- On the 'prop:' row set the ID to be the key name from the python tooltip above.
Note: this one is the name from the first part of the full Python path,
bpy.data.keys["Key"]in my case, so "Key".
- In the 'path:' row, paste in the copied shapekey path (in my case
key_blocks["Key 1"].value). That is, just the latter part of that full Py tooltip.