Community
Maya Forum
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reset Transform, Reset Scale, Reset Rotate, python script not working right. need feed back.

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
amaterasu-qbb
7201 Views, 5 Replies

Reset Transform, Reset Scale, Reset Rotate, python script not working right. need feed back.

I have created a simple python command and registered it as a hotkey.
The commands are as follows

 

  • ResetTransform (Alt+w)

 

import maya.cmds as cmds

cmds.move(0, 0, 0)

 

  • ResetRotate (Alt+e)

 

import maya.cmds as cmds

cmds.rotate(0, 0, 0)

 

  • ResetScale (Alt+r)

 

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.

キャプチャ32.PNG
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?

5 REPLIES 5
Message 2 of 6
mcw0
in reply to: amaterasu-qbb

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.

Message 3 of 6
amaterasu-qbb
in reply to: mcw0

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.

Message 4 of 6

Hi @amaterasu-qbb 

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;
}

 

 

Message 5 of 6
lynn_zhang
in reply to: amaterasu-qbb

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!





Lynn Zhang
Community Manager


Message 6 of 6

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.

Post to forums  

Technology Administrators


Autodesk Design & Make Report