1
$\begingroup$

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.)

$\endgroup$
1
$\begingroup$

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:

  1. Select your object with the keyframed shape key.
  2. 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: bpy.data.keys["Key"].key_blocks["Key 1"].value

Which tells us everything we need to use this in a driver.

  1. 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.

  2. Set the 'var' input variable to be a 'Single Property'.

  3. On the 'prop:' row set the ID Type (the small icon part) to "Key".
  4. 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".
  5. 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.

This appears to work and do what you asked. screenshot of driver edit window over shader editor

$\endgroup$

Your Answer

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