Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
linenumberstrue
import AtomsMaya
import tempfile

# parameters for the script
node = "tcAgentGroupNode1"
rig_scene = "/path/to/rig"
start = 1
end = 50

# find the agent ids, if no agent is selected we use all the agents
ids = cmds.getAttr("%s.agentSelection" % node)
if not ids:
    ids = list(range(len(AtomsMaya.getAgentGroup(node).agents())))

# exporting the fbxs
_, temp_fbx = tempfile.mkstemp('.fbx')
for i in ids:
    cmds.tcAtomsFbxExporter(fileName=temp_fbx, agentGroup=node, agentId=ids, frameStart=start, frameEnd=end)

# retargeting the fbxs on the animation rig
ma_files = []
for i in ids:
    _, temp_ma = tempfile.mkstemp('.ma')
	# the fbx exporter create fbx files with 4 digit padding
    file_path = temp_fbx.replace(".fbx", "%04d.fbx" % i)
    print file_path
    cmds.file(rig_scene, o=True, f=True)
    cmds.tcAnimationRigRetarget(fileName=file_path)
	# saving the file to a different temp location
    cmds.file(rn=temp_ma)
    cmds.file(save=True)
    ma_files.append(temp_ma)
    
# importing all the retargeted charactercharacters in a brand new scene
cmds.file(new=True, f=True)
for m in ma_files:
    cmds.file(m, i=True)
    
    

...