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?