How to toggle tweak mode across all three tools (move, scale, rotate)?

I am trying to write a simple function where I can toggle tweak mode (on/off) for all the transform tools at once. I can set tweak mode for one of the transform tools, manipMoveContext -e -tweakMode 1 moveSuperContext;, but if I switch to another tool, it will not be on. So I am trying to create a solution where, it will be to turned it on for all three tools, so that they stay in sync.

More or less I came up with the following:

string $currentCtx1 = `currentCtx`;
if ($currentCtx1 == "moveSuperContext"){
	string $state = !`manipMoveContext -q -tweakMode moveSuperContext`;
}else if($currentCtx1 == "RotateSuperContext"){
	int $state = (!`manipScaleContext -q -tweakMode scaleSuperContext`);
}else if($currentCtx1 == "scaleSuperContext"){
	int $state = (!`manipRotateContext -q -tweakMode RotateSuperContext`);
}

if ($state == 1){
	manipMoveContext -e -tweakMode 1 moveSuperContext;
	manipScaleContext -e -tweakMode 1 scaleSuperContext;
	manipRotateContext -e -tweakMode 1 RotateSuperContext;
}else{
	manipMoveContext -e -tweakMode 0 moveSuperContext;
	manipScaleContext -e -tweakMode 0 scaleSuperContext;
	manipRotateContext -e -tweakMode 0 RotateSuperContext;
}

But there are is a issue I cant find a way around; the rotate and scale tools tweakmode state cannot be queried if these tools are not active, this is unlike the move tool, whose state I can query, even if its inactive. I get the following error when I tried to query inactive scale/rotate tools:

this does not solve the issue: // Error: manipRotateContext: Object 'rotateSuperContext' not found.

searching around I have not found anything useful and ChatGPT is just leading me around in circles at this point.

How does one query the state of scale/rotate tools when they are inactive??

I am certain this is a very inefficient way to go about doing this sort of task, if someone knows of a “proper” or better way to do it I would love to know for sure. Thank you.

The problem you have described here is actually not the problem. Even if you switch to the scale tool and try to run:
manipScaleContext -e -tweakMode 0 scaleSuperContext;
you will get the same error. This is because, confusingly, scaleSuperContext is NOT the name Maya expects. The correct name for the manipScaleContext is Scale (I have no idea why).

You could fix your code above simply by changing all the manip names to Move, Rotate and Scale, however you would be reinventing the wheel somewhat.

In general, if you are just trying to replicate something Maya already does, you need to start by looking at what code it runs when you manually perform the function. You should also have noticed that when you enable tweak mode (manually) on ONE tool, it is already enabled on all three!

So toggle tweak mode manually (either in the tool options dialog, or by holding W, E, or R and left-clicking to open the respective viewport marking menu) and then see what the Script Editor reports. If nothing is reported, don’t give up, you just need to turn on Script Editor > History > Echo All Commands and then do it again!. You should see that toggling the tweak mode runs the code:
strsTweakMode true;
(among other junk as well, but you get to learn what code is irrelevant to what you are looking for fairly quickly)

Using the new whatIs trick you just learned in your earlier post, you should be able to do: whatIs strsTweakMode and should then find this MEL command is in a script:

...\\Autodesk\Maya202X\scripts\others\strsTweakMode.mel

and opening that in a text editor will show you all the code you need to do the job (and also show you the real manip names expected).

However, back to my earlier point about reinventing the wheel, you now have all the code you need, you don’t necessarily need to write anything. If you look in the MEL script you will see one of the functions there strsTweakModeDoIt already has a toggle mode, so if you want to toggle tweak mode on/off you just use the MEL command:
strsTweakModeDoIt 2;

[post edit caveat] - you may find after a restart of Maya, the new MEL command you are using no longer works. This is simply because Maya only sources some MEL scripts on demand, and if this happens, you simply need to source the script that contains your command. If for example you put strsTweakModeDoIt 2; on a hotkey, you would either add:
source strsTweakMode.mel
to your startup, or you could even add it to your hotkey code (but sourcing MEL scripts every time you press a hotkey is probably not a good idea)

1 Like

The problem you have described here is actually not the problem. Even if you switch to the scale tool and try to run:
manipScaleContext -e -tweakMode 0 scaleSuperContext;
you will get the same error. This is because, confusingly, scaleSuperContext is NOT the name Maya expects. The correct name for the manipScaleContext is Scale (I have no idea why).

Oh boy, so I was not going crazy, I spent a few more hours after asking here and discovered the above the hard way and cobbled the follwing:

//The following will toggle tweak mode for move,scale and rotate. keeping them in sync;
manipMoveContext -e -tweakMode (!`manipMoveContext -q -tweakMode moveSuperContext`) moveSuperContext;
manipScaleContext -e -tweakMode (!`manipScaleContext -q -tweakMode Scale`) Scale;
manipRotateContext -e -tweakMode (!`manipRotateContext -q -tweakMode Rotate`) Rotate;

It was all a blur and I dont even remember how I discovered the keywords Move,Scale and Rotate, I might have gleamed them from the Mel ref documentation.

In general, if you are just trying to replicate something Maya already does, you need to start by looking at what code it runs when you manually perform the function. You should also have noticed that when you enable tweak mode (manually) on ONE tool, it is already enabled on all three!

(emphasis mine), I swear I tested this last night, it was what set me on this task the whole time, imagine my shock when I tested it again after reading your post and it works as you said, am going crazy, that is the only explanation.

However, back to my earlier point about reinventing the wheel, you now have all the code you need, you don’t necessarily need to write anything. If you look in the MEL script you will see one of the functions there strsTweakModeDoIt already has a toggle mode, so if you want to toggle tweak mode on/off you just use the MEL command:
strsTweakModeDoIt 2;

Genius! this is perfect it works just as you describe on my end too.

I really appreciate this post, will keep your main point not reinventing the wheel in mind, also thank you for the heads about sourcing scripts after restarting Maya.

1 Like