I'm creating Blender scenes from scratch in a python script. In my script, I'm adding a custom property to cameras, like this:

  # Create a custom property "cp_zoom" on the Camera type (inherited by all camera objects)
  bpy.types.Camera.cp_zoom = bpy.props.FloatProperty(name="cp_zoom", default=1.0, description="Zoom from dsscene")
  print('Custom zoom:', camera.cp_zoom) # test that it's there on the actual camera

that works OK. I can see the cp_zoom custom prop in my camera props. But now I want to animate that custom property. Something like this pseudocode:

    if not camera.animation_data.action:
      camera.animation_data.action = bpy.data.actions.new(name=f'camera animation')
    fcurve = camera.animation_data.action.fcurves.new(data_path='cp_zoom', index=0)
    # Create the keyframes
    fcurve.keyframe_points.insert(frame=0, value=1)
    fcurve.keyframe_points.insert(frame=10, value=2)

I don't get any error, and I can see camera.animation_data.action.fcurves[0].data_path as cp_zoom, but the custom property doesn't get any animation in the resulting scene, and doesn't show up as animated in the blender UI. What am I missing?


Your Answer

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

Browse other questions tagged or ask your own question.