Get orientation values for camera from Python when using constraint?

I’m using a Track To constraint for the camera, but need the orientation (rotation) values. Unfortunately, they are not available though the normal means since the rotation values are not updated when using Track To. Is there any way I can get these values so I can use them with a script?

Just what exactly are you doing? What’s the scene like? Will it always be the same animation, or will it change based on user input (like in the game engine), or change depending upon a physic sim?

If it’s a simple one off thing, only doing it once, it’s set and never changing, and you only need a few values at specific frames, you could just key frame the camera bone. Inserting a normal rotational key frame won’t work here, because the bone isn’t actually rotating, it’s being constrained instead. Instead, if you insert a ‘visual rotation’ key frame, the key frame will be for the rotation as seen in the 3d view port. You could now remove the constraint, and the animation would be the same.

So think it thru from there… You could write a script to bake the constrained action, then access the values. If you need it to be more ‘real-time’ you could use a frame change event handler to insert the key frame for you, then access the value.

then again, thinking about it, since you’re wanting to access this data with a python script, why not ask in the python support section? Or search? I bet a few people have looked for the same thing…

Just a few thoughts,
Randy

Thanks. I need to change the frames of an image sequence texture based on the camera position. I can use the following operator with a frame change event:

bpy.ops.object.visual_transform_apply()

This works when I hit play, but it doesn’t when I actually render. This is using Cycles. I’ll try adding keyframes automatically as you suggested.

By the way, I forgot to mention I’m running Blender 2.71.

It seems frame change events don’t fire during rendering, so I had to set keyframes via Python after applying the camera orientation using visual_transform_apply(). Not ideal, but it does work.