2
$\begingroup$

I am trying to animate the focal length of the camera, based on focal length information imported from a file. setting the focal length is no problem:

focal_length = 35
timeline_frame = 10
cam = bpy.data.cameras.new('Camera')
cam.lens = focal_length

after setting this value I want to insert a keyframe for the focal length. According to my intuition, I am looking for something like this:

cam.keyframe_insert(data_path = 'lens', frame = (timeline_frame))

(this code deosn´t work...) is there any way to get this to work?

$\endgroup$
1
$\begingroup$

Your code works fine. But note that you are adding a new camera data when you do bpy.data.cameras.new('Camera'). If there already is a Camera data, the new one you created will be named Camera.001. Make sure this camera data is assigned to your camera object.

Assigning the camera data to the camera object

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.