Been searching for an answer to this for quite some time, but haven't been able to connect the missing pieces just yet!
My setup is this:
I have an armature, and an FBX object of a face with animation (Hence forth referred to as Face). I've created drivers on the armature that reference specific shape keys and values on the Face. This is my really cheap and dirty way to do facial motion capture, and I've gotten it working very well at the moment, but I've run into a slight issue. Each new capture I do has a new Face that I have to import. Thankfully, all of the shape keys are named the same, but the actual Key they use is a different number.
For now, I've been plugging in the new key each time I have to import a new Face model, but this takes a lot of time and I'd love to be able to run a script where I plug in the new Key number, and press go and it does it all for me, but have been unsuccessful. The closest I get is being able to get down to the driver itself, but I need a script that does a few things:
- Checks the selected armature for drivers
- Checks those drivers to ensure that the variable ID is set
- Change the variable ID to the correct one for each driver found
The path for the variable and value are all the same as well, I just need to change this one little thing and I'll have saved many hours of time. This is what I've gotten so far (Taken a bit from this post: How can I quickly and accurately find out if a bone is being used in any driver?):
import bpy def find_drivers(sel): objs =  for obj in sel: try: obj.animation_data.drivers except: pass else: objs.append(obj) return objs if not bpy.context.mode == 'POSE': sel = bpy.context.selected_objects objs = find_drivers(sel) driver_list = for obj in objs: for drv in obj.animation_data.drivers: if drv.driver.variables.targets.id.type == 'SINGLE_PROP': # Checks if the Variable Property type is set to Single Property if drv.driver.variables.targets.id == 'Key.068': # Check if the ID is set to the previous Key drv.driver.variables.targets.id = 'Key.094' # Change to the new key
Upon trying this though, nothing changes on the armature itself and I don't see any errors either. I'm quite a bit lost at this point, and any info that's out there is outdated as I'm on Blender 3.2, and a lot of coding changed past version 3.0. I'm also quite new to scripting and this is the closest I've gotten to anything touching the drivers on the armature in python, so I wouldn't be surprised if the whole thing was wrong. Can anyone help me or point me in the right direction on this?