Problems using load_and_retarget to load different bvh files onto multiple figures.

Hey everybody,

Just wondering if anyone has any insight on this problem… I’ve got a directory full of bvh files that are meant to be played simultaneously on different characters to make up my full scene. My goal is to start a blender scene with one makeHuman model, and then duplicate that model once for each bvh file, and load one bvh per model.

I’m doing fine with duplicating the models and putting them in the world where they should be, but when I get to the load_and_retarget step (bpy.ops.mcp.load_and_retarget) it ends up loading all the animations onto the first duplicate character made, and ignoring all the rest. Each time, the latest duplicate character is still selected, which I know because bpy.ops.transform operations work correctly.

This is (as far as I can tell) my last stumbling block, so any help would be most appreciated!

My code is below. The XML part of it is there because I’m saving an XML file out of my animation source application which gives the characters their world transforms. Everything is working fine except the load_and_retarget step.

Thanks!!

EDIT: sorry, spacing got killed in the upload, too bad this forum doesn’t have <code> markers!


import bpy
import os

from xml.dom.minidom import parse
from xml.dom.minidom import Node

#(These functions borrowed from Todd McIntosh on stackexchange.com)
def CheckSelectStatus§:
for c in p.children:
#print(c.name)
c[‘hideSelectWasTrue’] = False
if bpy.data.objects[c.name].hide_select == True:
bpy.data.objects[c.name].hide_select = False
c[‘hideSelectWasTrue’] = True
c.select = True
CheckSelectStatus©

def RestoreSelectStatusAndUnselect§:
for c in p.children:
if c[‘hideSelectWasTrue’] == True:
bpy.data.objects[c.name].hide_select = True
c.select = False
RestoreSelectStatusAndUnselect©

scene_path = “F:/bvhWork/Bigger_Nav_Test/”
full_path_to_xml = scene_path + “bvhExport.xml”

dom = parse(full_path_to_xml)
sceneShapeGroup = dom.getElementsByTagName(“sceneShapeGroup”)[0]

sceneShapes = sceneShapeGroup.getElementsByTagName(“sceneShape”)
for shape in sceneShapes:
id = int(shape.getAttribute(“id”))
name = shape.getAttribute(“name”)
groupID = int(shape.getAttribute(“shapeGroup”))
posX = float(shape.getAttribute(“pos_x”))
posY = float(shape.getAttribute(“pos_y”))
posZ = float(shape.getAttribute(“pos_z”))
rotX = float(shape.getAttribute(“rot_x”))
rotY = float(shape.getAttribute(“rot_y”))
rotZ = float(shape.getAttribute(“rot_z”))
rotA = float(shape.getAttribute(“rot_a”))
scaleX = float(shape.getAttribute(“scale_x”))
scaleY = float(shape.getAttribute(“scale_y”))
scaleZ = float(shape.getAttribute(“scale_z”))

if groupID == 1:  #arbitrary, we can make as many groups as we want

    #deselect everything
    bpy.ops.object.select_all(action='DESELECT')
    
    #select Jill, if group 1, musc_male if group 2
    jill = bpy.data.objects["Jill"]
    jill.select = True
    CheckSelectStatus(jill)
    
    #print (bpy.ops.object.name)
    
    #call duplicate_move
    bpy.ops.object.duplicate_move()
    
    #print (bpy.ops.object.name)
    
    #unselect Jill
    RestoreSelectStatusAndUnselect(jill)
    
    #translate, rotate, possibly scale new figure
    bpy.ops.transform.translate(value=(posX,posY,posZ))
    bpy.ops.transform.rotate(value=rotA,axis=(rotX,rotY,rotZ))
    
    #toggle pose mode on new figure
    #bpy.ops.object.posemode_toggle()
    #print(bpy.context.mode)
    bpy.ops.object.mode_set(mode='POSE', toggle=False)
    
    #call load and retarget with bvh path
    path_to_bvh = scene_path + str(id) + ".bvh"
    bpy.ops.mcp.load_and_retarget(filepath=path_to_bvh)

    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
    
    print (bpy.context.selected_objects)
    
    print ("sceneShapeID: " + str(id) + " name " + name + " group " + str(groupID) +
        " pos " + str(posX) + " " + str(posY) + " " + str(posZ) + " path " + path_to_bvh)        

dom.unlink()

FIXED!

I had to go into makeWalk code, in retarget.py, in loadRetargetSimplify, and change the target rig from context.object to context.selected_objects[0].

Whew!