Skip to main content
added 21 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

This answer doesn't address the FAST mode issue, it is another method to clear an fcurve and set new points that avoids looping either, reversing or using either the insert or remove methods of FCurve.keyframe_points entirely.

import bpy
frames = [1, 9, 20]
samples = [0, 8, 0]
# some action
a = bpy.data.actions["SomeAction"]
fc = a.fcurves[0] # some fcurve
dp, i = fc.data_path, fc.array_index
# clear the fcurve by removing it
a.fcurves.remove(fc)
# new one
fc = a.fcurves.new(dp, index=i)
# new points
fc.keyframe_points.add(count=len(frames))
# populate points
fc.keyframe_points.foreach_set("co", [x for co in zip(frames, samples) for x in co])
# update 
fc.update()

This answer doesn't address the FAST mode issue, it is another method to clear an fcurve and set new points that avoids looping either the insert or remove methods of FCurve.keyframe_points entirely.

import bpy
frames = [1, 9, 20]
samples = [0, 8, 0]
# some action
a = bpy.data.actions["SomeAction"]
fc = a.fcurves[0] # some fcurve
dp, i = fc.data_path, fc.array_index
# clear the fcurve by removing it
a.fcurves.remove(fc)
# new one
fc = a.fcurves.new(dp, index=i)
# new points
fc.keyframe_points.add(count=len(frames))
# populate points
fc.keyframe_points.foreach_set("co", [x for co in zip(frames, samples) for x in co])
# update 
fc.update()

This answer doesn't address the FAST mode issue, it is another method to clear an fcurve and set new points that avoids looping, reversing or using either the insert or remove methods of FCurve.keyframe_points entirely.

import bpy
frames = [1, 9, 20]
samples = [0, 8, 0]
# some action
a = bpy.data.actions["SomeAction"]
fc = a.fcurves[0] # some fcurve
dp, i = fc.data_path, fc.array_index
# clear the fcurve by removing it
a.fcurves.remove(fc)
# new one
fc = a.fcurves.new(dp, index=i)
# new points
fc.keyframe_points.add(count=len(frames))
# populate points
fc.keyframe_points.foreach_set("co", [x for co in zip(frames, samples) for x in co])
# update 
fc.update()
added 98 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

This answer doesn't address the FAST mode issue, it is another method to clear an fcurve and set new points that avoids looping either the insert or remove methods of FCurve.keyframe_points entirely.

import bpy
frames = [1, 9, 20]
samples = [0, 8, 0]
# some action
a = bpy.data.actions["SomeAction"]
fc = a.fcurves[0] # some fcurve
dp, i = fc.data_path, fc.array_index
# clear the fcurve by removing it
a.fcurves.remove(fc)
# new one
fc = a.fcurves.new(dp, index=i)
# new points
fc.keyframe_points.add(count=len(frames))
# populate points
fc.keyframe_points.foreach_set("co", [x for co in zip(frames, samples) for x in co])
# update 
fc.update()

This answer doesn't address the FAST mode issue, it is another method to clear an fcurve and set new points

import bpy
frames = [1, 9, 20]
samples = [0, 8, 0]
# some action
a = bpy.data.actions["SomeAction"]
fc = a.fcurves[0] # some fcurve
dp, i = fc.data_path, fc.array_index
# clear the fcurve by removing it
a.fcurves.remove(fc)
# new one
fc = a.fcurves.new(dp, index=i)
# new points
fc.keyframe_points.add(count=len(frames))
# populate points
fc.keyframe_points.foreach_set("co", [x for co in zip(frames, samples) for x in co])
# update 
fc.update()

This answer doesn't address the FAST mode issue, it is another method to clear an fcurve and set new points that avoids looping either the insert or remove methods of FCurve.keyframe_points entirely.

import bpy
frames = [1, 9, 20]
samples = [0, 8, 0]
# some action
a = bpy.data.actions["SomeAction"]
fc = a.fcurves[0] # some fcurve
dp, i = fc.data_path, fc.array_index
# clear the fcurve by removing it
a.fcurves.remove(fc)
# new one
fc = a.fcurves.new(dp, index=i)
# new points
fc.keyframe_points.add(count=len(frames))
# populate points
fc.keyframe_points.foreach_set("co", [x for co in zip(frames, samples) for x in co])
# update 
fc.update()
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

This answer doesn't address the FAST mode issue, it is another method to clear an fcurve and set new points

import bpy
frames = [1, 9, 20]
samples = [0, 8, 0]
# some action
a = bpy.data.actions["SomeAction"]
fc = a.fcurves[0] # some fcurve
dp, i = fc.data_path, fc.array_index
# clear the fcurve by removing it
a.fcurves.remove(fc)
# new one
fc = a.fcurves.new(dp, index=i)
# new points
fc.keyframe_points.add(count=len(frames))
# populate points
fc.keyframe_points.foreach_set("co", [x for co in zip(frames, samples) for x in co])
# update 
fc.update()