Override some hotkeys when using a certain tool (hotkeyCtx?)

Override some hotkeys when using a certain tool (hotkeyCtx?)

cesaratto
Explorer Explorer
674 Views
2 Replies
Message 1 of 3

Override some hotkeys when using a certain tool (hotkeyCtx?)

cesaratto
Explorer
Explorer

Hello, 

 

I am developing a plugin in Maya (C++), and have been making some brushes.

 

I was able to override global Maya hotkeys to achieve different features (modify the brush size...). 

 

I would like to override some hotkeys only when using my plugin / brushes. For that I have been looking at the Maya hotkey command with its example:

 

//    Here's an example of how to create runtimeCommand with  a certain hotkey context,
//    and map it to a key.
//

//    Create a command with "paintEffects" hotkey context.
//
runTimeCommand
	-annotation "Modify the Brush Size for the Paint Effects Tool"
	-category "MyPlugin"
	-commandLanguage "mel"
	-command ("print(\"Hello MyPlugin\");")
	-hotkeyCtx ("MyPlugin")
	ModifyBrushSize;

nameCommand
	-annotation "ModifyBrushSizeNameCommand"
	-sourceType "mel"
	-command ("ModifyBrushSize")
	ModifyBrushSizeNameCommand;

//    Assign the paintEffects as a hotkey context client.
//
hotkeyCtx -type "Tool" -addClient "MyPlugin";

//    Map a key to the newly created command.
//    When the Paint Effects Tool is activated, the b key will work within this tool and
//    override editor and application-wide contexts.
hotkey -keyShortcut "b" -name "ModifyBrushSizeNameCommand";

 

I replaced "paintEffects" with "MyPlugin" and tested the hotkeys in Maya.

The hotkey has been registered and is visible in the hotkey editor (as a custom script)

 

However when using my plugin / brushes, the global hotkey is executed not my custom command.

 

Could somebody explain how hotkeyCtx is supposed to work ? And how can I achieve making custom hotkeys for my plugin only ?

 

Thanks in advance

0 Likes
675 Views
2 Replies
Replies (2)
Message 2 of 3

stuzzz
Collaborator
Collaborator

What about using Qt QAction instead?

0 Likes
Message 3 of 3

cesaratto
Explorer
Explorer

Thanks for the reply, it may be a solution. 

 

According to the doc it is also possible to do it directly with Maya Mel or python. It works in the viewport correctly with PaintEffects but not with my plugin. I would like to know how to use it.

0 Likes