I have a script which generates a curve path and sets an object to follow the path, I can see the object moving correctly in the animation move, and it also moves to the correct location (at least visually in the view port, the coordinates when you press n do not change) when I use
bpy.context.scene.frame_set(desirved_frame). However, when I try to get the location and rotation of that object at the frame that I set, it just returns the original location of the object at frame 0. Below is the code I have used to generate the animation data and what I'm using to try and get the location.
curve = bpy.data.objects["curve"] follower = bpy.data.objects["Follower"] con = follower.constraints con.target = curve con.use_curve_follow = True bpy.ops.object.select_all(action='DESELECT') curve.data.use_path = True path_length_m = curve.data.splines.calc_length() time = path_length_m / car_v_mps target_fps = 30 length = int(target_fps * time) print("Frames is: ", length) anim = curve.data.animation_data_create() anim.action = bpy.data.actions.new("%s-Action" % curve.data.name) fcu = anim.action.fcurves.new("eval_time") mod = fcu.modifiers.new('GENERATOR') mod.coefficients = (-frame_start / length * 100, frame_start / length / frame_start * 100) def get_ext(scene, depsgraph): obj = scene.objects['Follower'] obj = obj.evaluated_get(depsgraph) print("Frame: ", scene.frame_current) print("Location: ", obj.location) scene = bpy.data.scenes #This is the only scene, == bpy.context.scene for frame in range(scene.frame_start, scene.frame_end): bpy.app.handlers.frame_change_post.append(get_ext) scene.frame_set(frame) bpy.app.handlers.frame_change_post.clear()
I have also tried replacing the final loop with:
for frame in range(scene.frame_start, scene.frame_end): scene.frame_set(frame) depsgraph = bpy.context.evaluated_depsgraph_get() ob = bpy.data.objects["Follower"] ob = ob.evaluated_get(depsgraph) print("Location: ", ob.location)
Both methods just print out the original location of the object.
Reading this documentation I'm not sure how I would use the examples they show to extract the evaluated location and rotation from the class they register, or how to even call the execute method.
Below are some solutions and answers I have read and attempted, with no success:
I'm really not sure what I'm doing wrong as some of the questions I've looked at are quite similar to my issue.
Thank you for any help you can provide.