Home Technical Talk

Maya component selection toggle

HomeGrownHeroz
polycounter lvl 6
Offline / Send Message
HomeGrownHeroz polycounter lvl 6
Hi, I'd like to create a hotkey to toggle between object, vert, edge and face mode. I've found a similar hotkey that toggles between move, scale and rotate and I believe it should work in the same way. I understand I need to use if and else statements but so far I have been unable to create what I want it to do.

Here's the code for the toggle script I found.

string $currentTool = `currentCtx`; 
if ($currentTool == "moveSuperContext")
setToolTo $gScale;
else if ($currentTool == "scaleSuperContext")
setToolTo $gRotate;
else
setToolTo $gMove;

Can someone help me create this toggle please? It would be such a time saver :)

Thanks

Replies

  • throttlekitty
    Offline / Send Message
    throttlekitty ngon master
    Here's a quick one that only toggles component modes with some copypasta inView messages from the F9,10,11 hotkeys.


    if (`selectType -q -pf` == 1){

    setSelectMode components Components; selectType -smp 1 -sme 0 -smf 0 -smu 0 -pv 1 -pe 0 -pf 0 -puv 0; HideManipulators;

    inViewMessage -smg "Vertex selection is now <hl>on</hl>.\nPress <hl>F8</hl> for object selection" -fade -pos topCenter;

    }

    else if (`selectType -q -pv` == 1){

    setSelectMode components Components; selectType -smp 0 -sme 1 -smf 0 -smu 0 -pv 0 -pe 1 -pf 0 -puv 0; HideManipulators;

    inViewMessage -smg "Edge selection is now <hl>on</hl>.\nPress <hl>F8</hl> for object selection" -fade -pos topCenter;

    }

    else if (`selectType -q -pe` == 1){

    setSelectMode components Components; selectType -smp 0 -sme 0 -smf 1 -smu 0 -pv 0 -pe 0 -pf 1 -puv 0; HideManipulators;

    inViewMessage -smg "Face selection is now <hl>on</hl>.\nPress <hl>F8</hl> for object selection" -fade -pos topCenter;

    }

  • HomeGrownHeroz
    Offline / Send Message
    HomeGrownHeroz polycounter lvl 6
    Thanks for that. I'm getting the error,

    // Error: line 19: Cannot find procedure "HideManipulators".

    Generally what is the best way to troubleshoot errors in Mel?
  • throttlekitty
    Offline / Send Message
    throttlekitty ngon master
    Which version are you using? I pulled the lines from 2016.5

    In this case, HideManipulators is a proc that lives in Maya2016.5/scripts/others/drInit.mel, and probably isn't necessary so you can try removing it from the lines using it.
  • HomeGrownHeroz
    Offline / Send Message
    HomeGrownHeroz polycounter lvl 6
    That is fantastic. Works brilliantly! Thanks so much for providing that. What part of the code is telling it to select vert, edge or face though?

    For example when I was trying to code this myself, I was trying to use the command, 'SelectVertexMask'.

    Also could you give me a hint as to how I'd figure out adding more to this script? I've really been enjoying playing with mel code so far and would like to start figuring more out as I go :D

    I'd love to be able to get it to cycle through Object and UV mode eventually.

    Thanks :)
  • throttlekitty
    Offline / Send Message
    throttlekitty ngon master
    Sure, the logic here is simple. Each "if" is testing which component mode is active, so it runs down the list until it hits a match. "selectType -q -pv == 1" returns true in vert mode (pv = polyVertex). Adding uvs into the mix would be a simple copy paste with a couple edits, check the maya documentation if the short names of the flags throw you off.

    I'm still not that great at scripting. I couldn't find a clean and simple way to detect object mode that still works for when multiple objects or nothing is selected, or maybe i'm overthinking it. I also question the sanity of adding that to the toggle, but that's just me. The default F8 hotkey has a simple toggle for object/component mode.
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    I couldn't find a clean and simple way to detect object mode that still works for when multiple objects or nothing is selected, or maybe i'm overthinking it. I also question the sanity of adding that to the toggle, but that's just me. The default F8 hotkey has a simple toggle for object/component mode.
    </code><pre class="CodeBlock"><code><br>//Query Object Mode, returns 1 or 0<br>selectMode -q -o;<br><br>//Query Component Mode, will return 1 even if no components are selected (cyan wireframe)<br>selectMode -q -co;
    If you use selectMode to enter component mode, it will switch to the last active component selection mode that was used.  If you have multiple objects selected, selectMode -q -o will return true as long as there is at least one object in your selection still in object mode.

    Personally I use a hotkey to toggle between Object and Multi modes.  Since Multi lets me pick all components, it's a bit more convenient than cycling through multiple modes.  You can also use getPanel -underPointer to make your component cycling context-sensitive to whatever window you're in.  For example, my hotkey that switches between Object and Multi modes is for my modeling viewports.  If I'm in the UV editor, it swaps between UVs and edges.

  • throttlekitty
    Offline / Send Message
    throttlekitty ngon master
    Ohh, I see now, thanks again Bartalon. What was throwing me off was that global object/component toggle. That query still returns true if the global mode is Object but I was using the RMB MM for vertex mode, which doesn't change the global mode.
  • maxshade
    Offline / Send Message
    maxshade polycounter lvl 2
    hey is there a wy to turn this in to a toggle button
    i guess it will nees some sort of mel scripting involving if statments or something like that

    anyway i found this

    resetPolySelectConstraint;
    polySelectConstraint -w 1 -m 2 -bo true -sh false;;

    if i run it it will allow me to select border edges 
    and it i only run 

    resetPolySelectConstraint;


    then i get back my regular selection
    (i guess it turns off the selectionConstraint or something)
    anyway i hope some way smarter and brilliant person 
    will help me make this in to a awsome mel toggle script that i then can assign to a hotkey

    sorry four my extremly bad english
  • Bodizzz
    Offline / Send Message
    Bodizzz polycounter lvl 9
    Hi, try this, toggle between vert, edge,face and object mode , just assign to a hotkey ;)

    if (`selectMode -q -o` == 1)
    {
       dR_modeVert;
       inViewMessage -pos topCenter -msg "Vert" -fade;
    }
    else if (`selectType -q -pv` == 1)
    {
       dR_modeEdge;
       inViewMessage -pos topCenter -msg "Edge" -fade;
    }    
       
    else if (`selectType -q -pe` == 1)
    {
       dR_modePoly;
       inViewMessage -pos topCenter -msg "Face" -fade;
    }   
       
    else if (`selectType -q -pf` == 1)
    {
       dR_modeObject;
       inViewMessage -pos topCenter -msg "Object" -fade;
    }
  • Bodizzz
    Offline / Send Message
    Bodizzz polycounter lvl 9
    maxshade said:
    hey is there a wy to turn this in to a toggle button
    i guess it will nees some sort of mel scripting involving if statments or something like that

    anyway i found this

    resetPolySelectConstraint;
    polySelectConstraint -w 1 -m 2 -bo true -sh false;;

    if i run it it will allow me to select border edges 
    and it i only run 

    resetPolySelectConstraint;


    then i get back my regular selection
    (i guess it turns off the selectionConstraint or something)
    anyway i hope some way smarter and brilliant person 
    will help me make this in to a awsome mel toggle script that i then can assign to a hotkey

    sorry four my extremly bad english
    Hello, try this

    dR_modeObject;
    dR_modeEdge;
    polySelectConstraint -sh true; 
    polySelectConstraint -sh false;
    polySelectConstraint -m 3 -t 0x8000 -w 1;
    polySelectConstraint -m 0;
Sign In or Register to comment.