Blender Asked by Fobos Demos on February 17, 2021
I have an armature with bones. Each bone has an animation data which iI’m trying to smooth.
fcurves = bpy.context.active_object.animation_data.action.fcurves
for curve in fcurves:
bpy.ops.graph.smooth()
But I don’t know in what context and how to get right access to the bones animation to smooth it by script.
Using Blender 2.8. I’d appreciate all the help I can get.
Basically, you have to take care of two things: first selecting the relevant bones you want to smooth and second to switch to the graph editor context. For some reason, selecting and deselecting the respective curves did not effect the operator. I rather locked the respective curves I did not want to smooth.
import bpy
# types = {'VIEW_3D', 'TIMELINE', 'GRAPH_EDITOR', 'DOPESHEET_EDITOR', 'NLA_EDITOR', 'IMAGE_EDITOR', 'SEQUENCE_EDITOR', 'CLIP_EDITOR', 'TEXT_EDITOR', 'NODE_EDITOR', 'LOGIC_EDITOR', 'PROPERTIES', 'OUTLINER', 'USER_PREFERENCES', 'INFO', 'FILE_BROWSER', 'CONSOLE'}
def smooth_curves(o):
current_area = bpy.context.area.type
layer = bpy.context.view_layer
# select all (relevant) bones
for b in o.data.bones:
b.select = False
o.data.bones[0].select = True
layer.update()
# change to graph editor
bpy.context.area.type = "GRAPH_EDITOR"
# lock or unlock the respective fcurves
for fc in o.animation_data.action.fcurves:
print(fc.data_path)
if "location" in fc.data_path:
fc.lock = False
else:
fc.lock = True
layer.update()
# smooth curves of all selected bones
bpy.ops.graph.smooth()
# switch back to original area
bpy.context.area.type = current_area
# deselect all (relevant) bones
for b in o.data.bones:
b.select = False
layer.update()
# currently selected
o = bpy.context.object
smooth_curves(o)
Answered by Janis on February 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP