Saturday, March 23, 2019

doodles











also i'm beginning to learn about modifying keyframes using blender python api.  here are some snippets that might be helpful for starting.

the array index tells if curves is x,y or z   array_index 0,1, or 2
>>> curves = bpy.context.selected_objects[0].animation_data.action.fcurves
>>> len(curves)
3

>>> print( curves[0].data_path, curves[0].array_index )
location 1

>>> print( curves[1].data_path, curves[1].array_index )
location 2

>>> print( curves[2].data_path, curves[2].array_index )
rotation_euler 0

can tell if curve has a key selected
>>> curves[1].select
True

>>> curves[2].select
True

#keyframes

>>> curves = bpy.context.selected_objects[0].animation_data.action.fcurves
>>> curves[0].data_path
'location'

>>> for key in curves[0].keyframe_points:
...     print(key.co[0],key.co[1])
...    
1.0 0.0
12.0 0.0
22.0 0.0

>>> for key in curves[2].keyframe_points:
...     print(key.co[0],key.co[1])
...    
1.0 0.0
12.0 2.8747828006744385
22.0 5.333418369293213

>>>

#this changes value of key
>>> curves[2].keyframe_points[1]
bpy.data.actions['SphereAction']...Keyframe

>>> curves[2].keyframe_points[1].co[1] = 3
>>>


#get whether a specific keyframe is selected
>>> curves[2].keyframe_points[2].select_control_point
False

>>>

#get selected key index in keyframe list
>>> for i in range(0, len(curves[2].keyframe_points) ):
...     if curves[2].keyframe_points[i].select_control_point:
...         print(i)
...        
1

#the previous and next key frame
>>> curves[2].keyframe_points[1-1].co[0]
1.0

>>> curves[2].keyframe_points[1+1].co[0]
22.0

>>>


Happy Sketching!
Nate