1
$\begingroup$
object.animation_data.action.fcurves

Always works on any object, but if try it on a camera

Python: Traceback (most recent call last): File "C:\Users\korb\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\plugin_init_.py", line 155, in execute cf = camera.animation_data.action.fcurves AttributeError: 'NoneType' object has no attribute 'action'

$\endgroup$
8
  • $\begingroup$ Going to need to see the script, but the NoneType suggests that camera isn't pointing to an actual object, or the object doesn't have animation data, because this works: >>> camera = C.scene.camera >>> camera.animation_data.action.fcurves bpy.data.actions['CameraAction'].fcurves $\endgroup$ Dec 3, 2021 at 21:16
  • $\begingroup$ Looking at the specifics of your error message, it looks like your camera doesn't have animation data. Because the 'NoneType' message refers to 'action', and not 'animation_data', by the way $\endgroup$ Dec 3, 2021 at 21:17
  • $\begingroup$ It does have animation data (focal lenght) $\endgroup$
    – Paulo Kim
    Dec 3, 2021 at 21:21
  • $\begingroup$ Python is telling you that it doesn't. Can you go to the Python cancel and type if camera.animation_data is None: print('oops') $\endgroup$ Dec 3, 2021 at 21:24
  • $\begingroup$ i got a oops on the terminal $\endgroup$
    – Paulo Kim
    Dec 3, 2021 at 21:26

1 Answer 1

1
$\begingroup$

To debug your problem, look closely at this part of the error message:

in execute cf = camera.animation_data.action.fcurves AttributeError: 'NoneType' object has no attribute 'action'

NoneType is telling you that one of the attributes of camera.animation_data.action.fcurves has no value and so it can't have an attribute.

action is telling you where Python had to stop parsing the variable. The attribute before action is animation_data. This tells you that camera has an empty animation_data attribute.

You confirmed this by running the suggested test:

if camera.animation_data is None: print('oops')

on the Python console. It printed "oops" verifying that the value of camera.animation_data was empty.

It turned out that the reason for this is because you had set camera incorrectly, perhaps by setting it to bpy.context.scene.camera or bpy.data.objects["Camera"]. That's because when you animated the focal length, (the variable is lens, by the way) The animation data was actually attached to bpy.data.cameras["Camera"].

So that means that the reference you need is bpy.data.cameras["Camera"].animation_data.action.fcurves.

This of course, is only true if there is only one camera and you haven't changed its name to something other than "Camera". In other cases, you'd have to find a different way to select the correct camera from bpy.data.cameras.

$\endgroup$

You must log in to answer this question.

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