Load and Retarget via bpy (Blender python)

I successfully retargeted a makehuman mesh (mhx) with a bvh file in blender using the python script.

bpy.ops.mcp.load_and_retarget

Is there a way to specify the number of frames to be retargeted? By default, it retargets only 250 frames.

My bvh has 880 animated frames. I edited the default value in props.py from 250 to 880 and it works fine. But this is not an authentic solution.

Could you please suggest a better solution.

According the manual you can use bpy.ops.import_anim.bvh operator to import a .bvh file:

bpy.ops.import_anim.bvh(filepath="", axis_up='Y', axis_forward='-Z', filter_glob="*.bvh", target='ARMATURE', global_scale=1.0, frame_start=1, use_fps_scale=False, use_cyclic=False, rotate_mode='NATIVE')

As you mentioned, next step is to Retarget, but it seems bpy.ops.mcp.load_and_retarget only works for the length of the current timeline (250 active frames by default).

Unfortunately there is no parameter to set the length of the animation and adjust the timeline in both methods. But if you know the length of the imported bvh, you can simply assign the value to Scene.frame_end between the execution of both methods:

scn = bpy.context.scene # get the current scene
# execute bvh operator
scn.frame_end = 777 # set new end frame
# execute retarget operator


To get the length of the bvh animation and set the end frame dynamically, find the last keyframe of the imported objects via actions or animation_data, see this answers: How to find number of animated frames in a scene via python?

Just struggled with this and the documentation hasn't improved, if anyone's wondering you just need to set:

bpy.context.scene.McpEndFrame = <your number of frames>