How to get the selected axis handle of a manipulator?

How to get the selected axis handle of a manipulator?

mcw0
Advisor Advisor
406 Views
2 Replies
Message 1 of 3

How to get the selected axis handle of a manipulator?

mcw0
Advisor
Advisor

I have an object selected and I'm in the rotate tool.  I run the following commands.

 

string $ctx = `currentCtx`;

The result is "RotateSuperContext".  I then wanted to query which axis is selected.

 

manipRotateContext -q -ah $ctx;

And I get this error.

// Error: line 1: manipRotateContext: Object 'RotateSuperContext' not found. //

How do I get the selected axis handle?

0 Likes
Accepted solutions (1)
407 Views
2 Replies
Replies (2)
Message 2 of 3

brentmc
Autodesk
Autodesk
Accepted solution

Hi,

 

First, super contexts are special in Maya and you would need to query the super context to get the actual tool name like this.

string $curContext = `currentCtx`;
string $curTool = (`superCtx -exists $curContext` ? `superCtx -q $curContext` : $curContext);


Second, the flag you want to query on the manipRotateContext is -currentActiveHandle / -cah

 

However, most Mel code in Maya just checks explicitly for the scale/rotate/move contexts using something like this since there is only a single context and they are called Move/Rotate/Scale.

int $activeHandle = -1;
string $curContext = `currentCtx`;
string $curTool = (`superCtx -exists $curContext` ? `superCtx -q $curContext` : $curContext);

if ($curTool == "Move") {
	$activeHandle = `manipMoveContext -q -currentActiveHandle $curTool`;
} else if ($curTool == "Rotate") {
	$activeHandle = `manipRotateContext -q -currentActiveHandle $curTool`;
} else if ($curTool == "Scale") {
	$activeHandle = `manipScaleContext -q -currentActiveHandle $curTool`;
}

if ($activeHandle == 0) {
    print "X handle is active";
} else if ($activeHandle == 1) {
    print "Y handle is active";
} else if ($activeHandle == 2) {
    print "Z handle is active";
} else if ($activeHandle == -1) {
    print "No active transform tool";
} else {
    print "Some other handle is active"; 
}
Brent McPherson
Principle Engineer
Message 3 of 3

Kahylan
Advisor
Advisor

Whoops I see this already got answered better by @brentmc

 

Nevermind 🙂

0 Likes