How do I query the current tool context in Mel?

How do I query the current tool context in Mel?

malcolm_341
Collaborator Collaborator
2,406 Views
5 Replies
Message 1 of 6

How do I query the current tool context in Mel?

malcolm_341
Collaborator
Collaborator

This doesn't work, what am I missing here?

 

string $currentToolName = `currentCtx`;


int $userToolMode = `manipMoveContext -q -mode $currentToolName`;

0 Likes
Accepted solutions (1)
2,407 Views
5 Replies
Replies (5)
Message 2 of 6

Rourker27
Contributor
Contributor

"manipMoveContext -mode" is looking for an int not the name of your current tool. What is it you are trying to do?


edit: Oh, this is a query, so you are trying to find the translation mode of your current tool?

0 Likes
Message 3 of 6

brentmc
Autodesk
Autodesk

Hi,

 

When dealing with tools like select/move etc. there are special contexts called "super contexts" which decide, based on the view, which context should process the mouse events. This is used to handle the fact that the actual select tool in the 3D view is different from the one in the UV editor etc.

The great news is there are lots of Mel scripts that ship with Maya and you can poke around those to see how things are done.

This example shows how bakeCustomToolPivot.mel decides if the move tool is active. It first checks the context and then just pulls the values from the "Move" tool. (since the move tool is always called "Move" in Maya)

string $currentCtx = `currentCtx`;
if ($currentCtx == "moveSuperContext"   || $currentCtx == "manipMoveContext") {
	// Move tool
	$customOri = `manipMoveContext -q -orientAxes Move`;

--

Brent

 

Brent McPherson
Principle Engineer
0 Likes
Message 4 of 6

Anonymous
Not applicable

Thanks for your replies, I'm trying to store the user's current select tool and then bring it back later after my script has finished so they don't lose their current tool mode. I was hoping a could do this with a query and then set that mode at the end of the script, I got it working, but this feels like more code than should be required to do something like this. Is there an easier solution?

//Store current tool
string $currentToolActive = `currentCtx`;

//Do some stuff here

//Bring back user tool
if(`gmatch $currentToolActive "*selectSuperContext*"`)
{
	SelectTool;
}
	
if(`gmatch $currentToolActive "*lassoSelectContext*"`)
{
	LassoTool;
}

if(`gmatch $currentToolActive "*artSelectContext*"`)
{
	artSelectToolScript 4;
}

if(`gmatch $currentToolActive "*moveSuperContext*"`)
{
	MoveTool;
}

if(`gmatch $currentToolActive "*RotateSuperContext*"`)
{
	RotateTool;
}

if(`gmatch $currentToolActive "*scaleSuperContext*"`)
{
	ScaleTool;
}
0 Likes
Message 5 of 6

brentmc
Autodesk
Autodesk
Accepted solution

Hi,

 

If you just want to save and restore the tool you can use the setToolTo command like this:

//Store current tool
string $currentToolActive = `currentCtx`;

//Do some stuff here

//Bring back user tool
setToolTo $currentToolActive;

--

Brent

Brent McPherson
Principle Engineer
Message 6 of 6

malcolm_341
Collaborator
Collaborator

Yes that's it, that's exactly what I was looking for. Thanks!

0 Likes