I have created a simple python command and registered it as a hotkey.
The commands are as follows
import maya.cmds as cmds
cmds.move(0, 0, 0)
import maya.cmds as cmds
cmds.rotate(0, 0, 0)
import maya.cmds as cmds
cmds.scale(1, 1, 1)
This command is usually useful, but there is a problem. For example, if you want to reset the controller of your character's rig, you can use The selected controller's Transform, Rotate and Scale move to the origin.
I want to reset the values in the Channel Box/Layer Editor to 0, 0, 0.
I'll use Animation Mentor's Stewart to explain this. (Data>AnimationMentor_Stewart)
arm Rotate is not zero, so run this. its working.
import maya.cmds as cmds
cmds.rotate(0, 0, 0)
But if you move your head and
import maya.cmds as cmds
cmds.move(0, 0, 0)
you'll notice that Channel Box / Layer Editor is not going to zero and is moving in a weird place.
It's happening in the rig I have, so I'm sure it's happening in all rigs as well.
What part of this command should I rewrite?
Solved! Go to Solution.
Solved by amaterasu-qbb. Go to Solution.
Solved by Abdulla-Qaladzay. Go to Solution.
The transform commands work in "spaces" ( world, local). It's better to use "setAttr" if you want the translate, rotate and scale values to be specific.
is this right?
# Reset Translate
cmds.setAttr(".translateX",0 )
cmds.setAttr(".translateY",0 )
cmds.setAttr(".translateZ",0 )
# Reset Rotate
cmds.setAttr(".RotateX",0 )
cmds.setAttr(".RotateY",0 )
cmds.setAttr(".RotateZ",0 )
# Reset Scale
cmds.setAttr(".ScaleX",1 )
cmds.setAttr(".ScaleY",1 )
cmds.setAttr(".ScaleZ",1 )
Is there any way to make this cmds.setAttr("pSphere1.translateZ",0 ) run on the selected object without specifying a name?
The selection is cmds.ls( selection=True ), but I don't know how to use it.
as @mcw0 said we need to be more specific of how we want to move
in this state we need to use -ls (local space)flag or -os (object space) flag:
//mel vestion
move -ls 0 0 0;
if we do not define the space by default Maya apply the command with -ws flag(world space).
if we freeze the transform for a child object that have an offset group as parent then apply this command
move -ws 0 0 0
the offset of the parent will not work, the "head controller" must have an offset group that is why this is happen
watch video attachment "originAffterFreezTransfoms.mp4"
if we use setAttr for a single object we do not need to identify the name of the object
but if we use the command for more than one object then we need to specify the names
so for solve that we need to create a string array and use a loop to apply the command for all the objects one by one:
//MEL vestion
string $araSelect[]=`ls -sl`;
for($all_c in $araSelect){
setAttr ($all_c+".translateX") 0;
setAttr ($all_c+".translateY") 0;
setAttr ($all_c+".translateZ") 0;
}
Hello @amaterasu-qbb ,
Just checking to see if your problem has been solved. Have you tried the above suggestions from @Abdulla-Qaladzay and did you have any success? If you find the suggestions helpful, please click on the "ACCEPT SOLUTION" button in his reply so this helps other users in the community find the solution too. Thanks!
Sorry for the late reply. I tried to make your mel into Python. (I don't know if that's correct, but it worked fine for me.)
import maya.cmds as cmds
#Reset transform
cmds.move(0, 0, 0, ls=True)
If you have a rig that doesn't work, I'm 100% sure with your mel.
//mel vestion
move -ls 0 0 0;
Even if I don't use setAttr, I think it's safe for the time being in my case anyway.
Thanks.
If my command doesn't work, anyone can post here.
Reset Transform
import maya.cmds as cmds
#Reset transform
cmds.move(0, 0, 0, ls=True)
Reset Rotate
import maya.cmds as cmds
#Reset rotate
cmds.rotate(0, 0, 0)
Reset Scale
import maya.cmds as cmds
#Reset scale
cmds.scale(1, 1, 1)
Can't find what you're looking for? Ask the community or share your knowledge.