0
$\begingroup$

I'm following this tutorial for face tracking and used a few lines of code to add the face mesh as a depth target for all the trackers which are empties. Actually, I just wrote the lines from the tutorial but somehow it does not work in my file.

import bpy

for tracker in bpy.data.objects:
    if tracker.type == 'EMPTY':
        bpy.context.view_layer.objects.active = tracker
        bpy.context.object.constraints["Follow Track"].depth_object = bpy.data.objects["FBHead"]

Code

$\endgroup$

1 Answer 1

0
$\begingroup$

Your clue is in the error message:

KeyError: 'bpy_prop_collection[key]: key "Follow Track" not found'

Your code is accessing bpy.context.object.constraints["Follow Track"] but it says your file cannot find any Follow Track Constraint with the name "Follow Track". So one possibility is that it probably is named differently so you need to check the tracker's Object Constraint Properties and adjust the name either in your script or in the field in red box marked as shown:

enter image description here

The other possible scenario is that there are other empties in your scene that are not trackers. So you need to further filter these out. They most likely do not have the FOLLOW_TRACK constraint type so you should use this code:

import bpy

for tracker in bpy.data.objects:
    if tracker.type != 'EMPTY':
        continue
    for c in tracker.constraints:
        if c.type != 'FOLLOW_TRACK':
            continue
        bpy.context.view_layer.objects.active = tracker
        bpy.context.object.constraints["Follow Track"].depth_object = bpy.data.objects["FBHead"]

Then make sure you have the object with name FBHead because you are using that in your script bpy.data.objects["FBHead"]

$\endgroup$
2
  • 1
    $\begingroup$ For me solution 2 solved the problem. I had another empty in the scene. Deleting the empty solved it and your code worked as well, thank you so much! $\endgroup$
    – user123511
    Sep 12, 2022 at 8:12
  • $\begingroup$ no prob! glad it resolved your issue :) $\endgroup$ Sep 12, 2022 at 10:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .