Relocate animation by script.

Relocate animation by script.

manuel.spkDKCCG
Contributor Contributor
1,079 Views
3 Replies
Message 1 of 4

Relocate animation by script.

manuel.spkDKCCG
Contributor
Contributor

Hello!
I need to export animations starting at the point (0,0,0). In Maya I achieve this in a simple way using a Relocator, but I can't figure out how to do it by script.
I'm trying to do It in Python with cmds, but I cant find any command to relocate.

What would be the easiest way to do it?
Thanks!

0 Likes
Accepted solutions (1)
1,080 Views
3 Replies
Replies (3)
Message 2 of 4

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

I took a look at your problem. From what I could find in the documentation and when looking at the nodes it seems that the relocate object is basically just a transform node that feeds its Xform Matrix into the OffsetMatrix of the Clip and the Root object feeds its Message Attribute into the root Obj Attribute of the Anim Clip.

However whenever I tried to connect the Message Attribute by hand or via code it just kept crashing my Maya, so there needs to be som connection I'm missing.

But there is another way to trigger the command using the mel.eval command. This command takes a string from a python program and exectues it in the MEL interpreter.

 

import maya.mel as mel

mel.eval('teCreateRelocator(-1)')

This script will just run the createRelocator command from the Time Editor. Sadly the only way of feeding it the clip it needs to create a relocator for is by selecting it. So you will need to add some code to select the correct clip before this part of the programm runs.

This command also does not return a value, so you will have to define the variable to further use the relocator by using string formating.

 

So a script to move a clip to 0,0,0 would look something like this:

 

import maya.cmds as mc
import maya.mel as mel

c = "anim_Clip1.clip[0]"
mc.select(c)

mel.eval('teCreateRelocator(-1)')

rL = c[:-8] + "_Relocator"

mc.xform(rL, t= (0,0,0), ws = True )

Obviously all of this isn't really nice programming because of the reasons mentioned above, but it works...

 

I hope this helps!

0 Likes
Message 3 of 4

manuel.spkDKCCG
Contributor
Contributor

Hi Kahylan. Thanks!

It works great. I wish there was more documentation on this, because It's hard for me to figure out what Maya is doing in the background. Thanks again!

In case It can help someone, I used this workaround by using an animation layer, and the inserting a 0,0,0 keyframe in the first frame of the main controller.

 

cmds.select("CHARACTER:C_main_global") #your main rig controller that defines position
cmds.animLayer("AnimLayer1")
cmds.setAttr("AnimLayer1.rotationAccumulationMode", 0)
cmds.setAttr("AnimLayer1.scaleAccumulationMode", 1)
cmds.animLayer("AnimLayer1", edit=True, addSelectedObjects=True)
cmds.currentTime( 0, edit=True ) #or whatever your first frame is
cmds.move( 0, 0, 0 )
cmds.setKeyframe()

 

 

Not the most beautiful solution in the world, but... It works.

Message 4 of 4

JimDIV
Community Visitor
Community Visitor

 

cmds.timeEditorClipOffset() is the command you may be interested in.
0 Likes