Home Technical Talk

Tutorial for context sensitive mel script/hotkeys in Maya?

dive
polycounter lvl 6
Offline / Send Message
dive polycounter lvl 6
Hey Guys, 

Are there any examples/tutorials out there to set up simple context dependent hotkeys in maya, based on selection type and selection count

for example if faces are selected execute selectadjacentface.mel, or selectadjacentvertex.mel for vertex selection, etc?

Replies

  • eltarbos
    Options
    Offline / Send Message
    eltarbos polycounter lvl 7
    Hi,
    You can try to make a procedure to return the type of the selection. Something like this:
    proc string returnSelectType()<br>	{<br>	string $selectionType = "";<br>	if (size(`filterExpand -ex true -sm 12`) !=0) {<br>		$selectionType = "object"; }<br>	if (size(`filterExpand -ex true -sm 9`) !=0) {<br>		$selectionType = "curve"; }<br>	if (size(`filterExpand -ex true -sm 32`) !=0) {<br>		$selectionType = "edge"; }<br>	if (size(`filterExpand -ex true -sm 31`) !=0) {<br>		$selectionType = "vertex"; }	<br>	if (size(`filterExpand -ex true -sm 34`) !=0) {<br>		$selectionType = "face"; }		<br>	return $selectionType;<br>	}<br>string $sel[0] = `ls -sl`;<br>if (returnSelectType() == "object") { <br>    print ("the selected object is: "+ $sel[0]);}<br>else {<br>    print ("the type of the selection is: "+ returnSelectType());}




  • Justo
    Options
    Offline / Send Message
    Justo polycounter
    ooooh eltarbos, that's a good-looking template. 
  • dive
    Options
    Offline / Send Message
    dive polycounter lvl 6
    Thanks so much for the reply Eltarbos!

     I haven't scripted anything so I just wanted to make sure, for selection count, would I then modifiy this template with
    https://help.autodesk.com/cloudhelp/2016/CHS/Maya-Tech-Docs/Commands/polyEvaluate.html

    For example if 2 edges are selected that share an open face I'd like to run bridge, but if 2 edges are on the same row I'd like run connect edge, if one edge is selected I'd like to split the edge with a vertex... 

    This might be way to advanced for a non scripter but I was curious because I badly want to optimize my hotkeys in Maya similar to what has been done in Max already haha
  • eltarbos
    Options
    Offline / Send Message
    eltarbos polycounter lvl 7
    You don't have to use "polyEvaluate". You can also use "size" to return the number of selected components.
    The main difficulty of what you try to achieve is to return the position of the components. It's not so easy to test if a component is on the same row as another one.
  • dive
    Options
    Offline / Send Message
    dive polycounter lvl 6
    Ah you're right, I appreciate the help however. Some advanced scripting would be needed to test for adjacency and if something. 

    Is size a mel command? your template + size would allow me at least 6 commands tied to macro, like 1 edge vs more than 1, and for face and vertex, and even object 
  • eltarbos
    Options
    Offline / Send Message
    eltarbos polycounter lvl 7
    Yes "size" is a mel command to return the number of items stored in a list.
Sign In or Register to comment.