Home Technical Talk

Set Align to edge as a hotkey in maya?

polycounter lvl 13
Offline / Send Message
artquest polycounter lvl 13
Does anyone know if it's possible to set the align to edge option for the translate tool in maya to a single hotkey?

The tool option is hidden inside menus and it's slowing down my workflow. The marking menu for this is ok but I'd rather not have to select the option and pick an edge, I'd like it to use whatever I already have selected or 1 step better, whatever my mouse is hovering over via pre-selection highlighting.


My goal is to eventually build a mel or python script (if it's possible) that uses pre selection highlighting to grab whatever edge my mouse is hovering over and then run the align to edge command without having to click anything and then assign it to a hotkey.

Perhaps this script or something similar already exists? If so I'd love to know where to find it!

Replies

  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    Hey, I tested this real quick on a cylinder and it seems to work. It sets your preselection as the move tool's orientation, keeps you in edge mode, and retains your current selection. Let me know
    if( !`exists doMenuComponentSelection` ) eval( "source dagMenuProc" );
    if( !`exists manipScaleAlignHandleWith` ) eval( "source manipScaleOrient" );
    if( !`exists manipMoveAlignHandleWith` ) eval( "source manipMoveOrient" );
    
    {
        string $current[] = `ls -sl`;
        string $sel[] = `ls -psh`;
        if ($sel[0] != "") {
            string $obj[] = `listRelatives -p $sel[0]`;
    // uncomment next line if you want to also align scale tool
    //        manipScaleAlignHandleWith($sel[0], {$obj[0]});
            manipMoveAlignHandleWith($sel[0], {$obj[0]});
            doMenuComponentSelection($obj[0], "edge");
            select $current;
        }
    }
    
  • artquest
    Offline / Send Message
    artquest polycounter lvl 13
    Awesome! This is exactly what I was looking for. My experience in mel is pretty limited and it probably would have taken forever for me to write this so I very much appreciate it!

    Thanks Bartalon!

    P.S. For me It's not retaining the current selection for some reason. I'm using maya 2014 extension.

    EDIT: Seems like I have to click somewhere in the viewport for it to realize that it still has something selected. Anyway around this? Also perhaps instead of keeping the current(old) selection it could make the pre-selection the newly selected edge?
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    How's this
    if( !`exists doMenuComponentSelection` ) eval( "source dagMenuProc" );
    if( !`exists manipScaleAlignHandleWith` ) eval( "source manipScaleOrient" );
    if( !`exists manipMoveAlignHandleWith` ) eval( "source manipMoveOrient" );
    
    {
        string $sel[] = `ls -psh`;
        if ($sel[0] != "") {
            string $obj[] = `listRelatives -p $sel[0]`;
    // uncomment next line if you want to also align scale tool
    //        manipScaleAlignHandleWith($sel[0], {$obj[0]});
            manipMoveAlignHandleWith($sel[0], {$obj[0]});
            doMenuComponentSelection($obj[0], "edge");
            select $sel;
        }
    }
    

    Now it will change to your selection to whatever your preselection is. Also I didn't get any issues with the selection mode not being recognized. Let me know if the problem persists and I'll look into it.
  • artquest
    Offline / Send Message
    artquest polycounter lvl 13
    Bartalon wrote: »
    How's this
    if( !`exists doMenuComponentSelection` ) eval( "source dagMenuProc" );
    if( !`exists manipScaleAlignHandleWith` ) eval( "source manipScaleOrient" );
    if( !`exists manipMoveAlignHandleWith` ) eval( "source manipMoveOrient" );
    
    {
        string $sel[] = `ls -psh`;
        if ($sel[0] != "") {
            string $obj[] = `listRelatives -p $sel[0]`;
    // uncomment next line if you want to also align scale tool
    //        manipScaleAlignHandleWith($sel[0], {$obj[0]});
            manipMoveAlignHandleWith($sel[0], {$obj[0]});
            doMenuComponentSelection($obj[0], "edge");
            select $sel;
        }
    }
    

    Now it will change to your selection to whatever your preselection is. Also I didn't get any issues with the selection mode not being recognized. Let me know if the problem persists and I'll look into it.

    You rock man.
    Everything is working perfectly :)

    One last question! :D

    Ok. So first off I've decided that my main usage will be your original script with retaining the current selection (the other one will be a secondary situational hotkey).

    Is it possible to make the script switch back to multi component mode? Right now it drops me back into edge only mode. Which is fine except that when switching to multi mode manually after running the script it clears my selection as it enters multi component mode. (On the original script that keeps current selection)

    I tried turning on echo all commands in the script editor but there was just too much going on in there to figure out exactly what Code I needed to switch back to multi-component selection mode. It's not a huge deal if it doesn't work. You've already given me a huge productivity boost. :)

    I think it may be an inherent flaw in maya because it doesn't save multi component selections by default like it does with individual component modes.

    EDIT: I also noticed that after using the "reset tool" option or selecting world space in the radial menu to go back to world space that the script no longer sets the translate tool to use a custom axis, even though I can see the custom axis changing in the tool settings box when using the script.
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    artquest wrote: »
    I tried turning on echo all commands in the script editor but there was just too much going on in there to figure out exactly what Code I needed to switch back to multi-component selection mode. It's not a huge deal if it doesn't work. You've already given me a huge productivity boost. :)

    Yeah, I can't stand Maya 2014 because of the constant script editor feed so I usually work in 2013. This also means I don't have a whole lot of experience writing for things involving the Modeling Toolkit.

    Glad I was still able to be some help, maybe someone else can modify what I have to work with the Modeling Toolkit. :)

    P.S. I updated the script in my first post, the one that retains current selection instead of switching to the preselection.
  • artquest
    Offline / Send Message
    artquest polycounter lvl 13
    I made a few small changes. Now no matter what you had set in the tool options it will jump to using the custom axis now every time you run it. Before I was having to go back to the tool options menu anyway to change the options before it would give me access to the axis it had created.

    Also it will now return you to multi component mode! :D
    if( !`exists doMenuComponentSelection` ) eval( "source dagMenuProc" );
    if( !`exists manipScaleAlignHandleWith` ) eval( "source manipScaleOrient" );
    if( !`exists manipMoveAlignHandleWith` ) eval( "source manipMoveOrient" );
    
    {
      
        string $current[] = `ls -sl`;
        string $sel[] = `ls -psh`;
        if ($sel[0] != "") {
            string $obj[] = `listRelatives -p $sel[0]`;
       
    // uncomment next line if you want to also align scale tool
            manipScaleAlignHandleWith($sel[0], {$obj[0]});
            manipMoveAlignHandleWith($sel[0], {$obj[0]});
            doMenuComponentSelection($obj[0], "edge");
            manipMoveContext -e -mode 6 Move;       
            doMenuComponentSelection($obj[0], "meshComponents");
            select -add $current;
            
    
        }
    }
    
  • Brygelsmack
    Offline / Send Message
    Brygelsmack polycounter lvl 11
    Sorry for the bump. Is there a way to do this in Maya 2015, SP6? I can't get the MEL in this thread to work. 
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    I'll look into it some time this week :)
  • Brygelsmack
    Offline / Send Message
    Brygelsmack polycounter lvl 11
    Thanks man! That's very nice of you. 
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    Alright I think I got it working again for 2015 and 2016.  Let me know if there are any issues. 

    If in Edge, Face, or Multi mode, the script will look at what's pre-selected and set your manipulator to that edge's axis (or face normal).  Running the script while nothing is pre-selected will reset the axis orientation settings (default is Object).  Running the script with a vertex pre-selected will do nothing.

    {

  • beefaroni
    Offline / Send Message
    beefaroni sublime tool
    Oh this is super interesting. I was doing it by remapping "S" to a marking menu. Thank you for posting this!

  • throttlekitty
    Preselect query works from a marking menu?
  • beefaroni
    Offline / Send Message
    beefaroni sublime tool
    Preselect query works from a marking menu?
    Preselect query?
  • throttlekitty
    beefaroni said:
    Preselect query works from a marking menu?
    Preselect query?
    Bartalon's script looks at the component you're hovering over; or "pre-selected" when you run the script via hotkey. I'm too tired and cranky to mess with more Maya to see how that works in a marking menu, I thought that's what you set up. :)
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    Your marking menu gives me an idea, beefaroni.  Later today I'm going to update the script to use orientation of faces / vertices if selected rather than doing nothing, because why not
  • Brygelsmack
    Offline / Send Message
    Brygelsmack polycounter lvl 11
    Thanks for giving this a go! I'm trying to run it like this but can't seem to make it work. Am I doing it wrong? 

    https://streamable.com/18xq
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    It's set up to work with pre-selection only, so if your mouse is in the Script Editor to run it, there won't be any pre-selection to query.  You'll want to set it up as a custom hotkey for it to work properly.

    If you just want to test the script, make sure the script editor is active and, before executing the code, make sure your mouse is hovering over a component in the viewport.
  • Klaudio2U
    Offline / Send Message
    Klaudio2U polycounter lvl 8
    What does this script do?
    Set the align to edge option for the translate tool? Align? Edge? to what, where? 
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    It sets any edge that is pre-selected under your cursor as the active component and sets the axis orientation to "component" so the manipulator will be aligned to the direction of that edge.  If a face is pre-selected, orientation will be set to that face.  Using the script with no pre-selected component will reset the manipulator's axis orientation to regular object space.  It does what OP asked for way back when and a little extra.
  • Klaudio2U
    Offline / Send Message
    Klaudio2U polycounter lvl 8
    Ah ok i see. Thanks.
    I was kind of confused what exactly he means here and that the tool option is hidden inside menus...

    Still can't see why the script for this when you can just hold W, E or R key + LMB and in marking menu choose mode you need. 
    Well, i guess we all have our own workflows so.. :) 

  • Brygelsmack
    Offline / Send Message
    Brygelsmack polycounter lvl 11
    Bartalon said:
    It's set up to work with pre-selection only, so if your mouse is in the Script Editor to run it, there won't be any pre-selection to query.  You'll want to set it up as a custom hotkey for it to work properly.

    If you just want to test the script, make sure the script editor is active and, before executing the code, make sure your mouse is hovering over a component in the viewport.
    I see. But even when I do that (I set it to Alt-Shift-X for now) it's not doing anything when I hover over an edge I want to align my manipulator to. :neutral:

    Edit: Nvm, it works but not how I imagined. 

    https://streamable.com/1hft

    Edit2: Third time's a charm. :blush:

    https://streamable.com/4vcm

    First time I'm running the script it seems like it sets the manipulator to Normal average. Second time I run it sets to to edge, which is exactly what I want. 
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    It should be doing this D:



  • Brygelsmack
    Offline / Send Message
    Brygelsmack polycounter lvl 11
    Yeah it's just switching to Normal average the first time I run it, then the second time it does what I want it to.

    https://streamable.com/g7nv
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    Looks like I didn't test it against a complex enough shape the first time around in 2015 so I missed that.  I'll fix up the script & edit this post when it's working properly.

    [EDIT]
    Script should now behave properly for 2015 and 2016.  Works on faces and edges, but not vertices (for now, unless someone really wants it).
  • Brygelsmack
    Offline / Send Message
    Brygelsmack polycounter lvl 11
    Cheers! Appreciate that mate.
  • beefaroni
    Offline / Send Message
    beefaroni sublime tool
    Hmm. So with the hotbox setup I have. I can align my manipulator to an edge, switch to another component (face/vertex/etc) and then select "custom axis" to go back to the manipulator I saved. With this, it seems to "forget" when I go to custom axis.
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    Nice catch beefaroni.  You just need to change the -mode value on line 30 from 9 to 6.
    I updated the script above as well.
  • oglu
    Offline / Send Message
    oglu polycount lvl 666
    in maya 2017 just hold down D and LMB click onto an edge to snap the pivot...
    D + RMB will also pin the pivot...
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    oglu said:
    in maya 2017 just hold down D and LMB click onto an edge to snap the pivot...
    D + RMB will also pin the pivot...
    This is the case for 2016 as well, but not 2015 and older, so this should help bridge the gap a little.
Sign In or Register to comment.