Baking Location From Animation Derived From Constraints?

Hi All,

I have an empty that moves between two points. It moves because it has two COPY_LOCATION constraints (with the two points as the targets) applied to it. The two influence slider are animated to make the empty move.

So I want to turn that animation into a “real” keyframe location animation then discard the constraints. But because the location is always the same, the bake routine I use makes a bunch of keyframes that are always the same value.


            ob_reframe = bpy.data.object["re_frame"]
            localScene = bpy.data.scenes[0]
            fs = 1  #localScene.frame_start
            fe = localScene.frame_end
            frame_current = localScene.frame_current
            
            # We have our source, our target and an action.
            for fc in range(fe-fs):
                localScene.frame_set(fc)    # Change the frame.
                ob_reframe.location = ob_reframe.location * ob_reframe.matrix_world
                localScene.update()
                ob_reframe.keyframe_insert(data_path="location", frame=fc)

How do I get the true location of an object that is being positioned by a constraint?
Then, after I have that value, how do I insert a keyframe with that value so it actually works?

see the Animation / Using Low-Level Functions code at http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro… that should do it I think

i would suggest
save the location
set location to the world_matrix.to_translation()
insert the keyframe
set location back to the saved one
go to next frame

and repeat this for all wanted frames. This creates the keyed location
for the real position of the object, then you can use this action and
disable the constraints …

btw. if rotation is needed too, you have to do the same save, set world-rotation, restore rotation…

edit: the lines in your code - change to something like:
old_location = obj.location
obj.location = obj.matrix_world.to_translation()
insert-keyframe …
obj.location = old_location

@test-dr: Thank you , that worked.
Here is the revised code.


            localScene = context.scene
            fs = 1  #localScene.frame_start
            fe = localScene.frame_end
            frame_current = localScene.frame_current
            
            isBusy = True
            # Make a list of locations.
            for fc in range(fe-fs):
                localScene.frame_set(fc)    # Change the frame.
                old_loc = ob_reframe.location
                ob_reframe.location = ob_reframe.matrix_world.to_translation()
                ob_reframe.keyframe_insert(data_path="location", frame=fc)
                ob_reframe.location = old_loc
            isBusy = False

@liero: My first attempt used some of the low-level functions, but I am still having problems with naming things correctly and would end up with channels in the Graph Editor that were not correctly linked and underlined in red.