0
$\begingroup$

I am attempting to make an addon/script with blender python that works with mocap files (.bvh), my problem is that when the files are imported the group collection on fcurve.group is blank

for fcurve in bpy.context.active_object.animation_data.action.fcurves:
        if fcurve.group is not None:
            print(text='Source object fcurve group ' + fcurve.group.name)

How do I create and assign a group to the fcurve with python script?

fcurve.group = bpy.types.FCurve.new("LocRot") #what i tried first

Explanation of why: When i import the files they have rotation mode XZY Euler on all the bones, I am attempting to use this script to convert the rotation mode to Quaternion however it fails due to the fact that the bones have no groups on them.... (hence my question)

Ultimately I plan to make my own pipeline which handles the small problems I have with the .bvh files when imported, such as converting FK -> IK

My full code can be found here and here if that helps at all

UI so far

$\endgroup$
  • $\begingroup$ Why is this a problem? What do you do with the BVH files that Blender's importer doesn't do already? $\endgroup$ – dr. Sybren Jan 21 '18 at 22:43
  • $\begingroup$ dr Sybren: all i am trying to do is assign a new group to an fcurve, do you know how to do it? fcurve.group = bpy.types.FCurve.new("LocRot") looked promising however i don't think i used it right cause it didn't work here $\endgroup$ – Alpha Jan 21 '18 at 23:02
2
$\begingroup$

Both the fcurves themselves, and the action groups are part of the action object. You have to create new groups through the action and then assign that group to any fcurves you want inside it.

armature = bpy.context.scene.objects.active
anim_data = armature.animation_data
action = anim_data.action

# create a new group
group_1 = action.groups.new("group_1")

# assign the first three fcurves to the new group
for fcurve in anim_data.action.fcurves[:3]:
    fcurve.group = group
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.