Home Technical Talk

[WIP] - Maya - Rapid Select Tool

polycounter lvl 18
Offline / Send Message
Illusions polycounter lvl 18
Version Edit: Script should work now w/o any editing.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

I've been working on a script for rapidly selecting every n edge, and would like to get some feedback and suggestions on the script itself, and its potential future features. I would like to both gauge its usefulness, what features people would like to see in it, and also whether or not a script that already does what it does, or what I would like it to do, already exists (so as to not waste time making a duplicate of an already existing script).

Download Script

Since, at the moment, its short on in script commentary and explanations...

How to Use

Select an edge, edge loop, or edge ring you'd like to start with, then start the script.

The feature that makes this script a bit different are:

That I tried to make it as quick to select things as possible, by limiting the need to remove your hand from your mouse or tablet pen to enter numbers, and also by unburying certain selection oriented features from menus.

You can interactively see what your final selection will be. Whatever your initial selection is when the script starts will be what is used when making selections. So lets say you hit the Quick Select by Number 2 button, and you don't like the resulting selection. You don't have to undo, or re-select your original selection. Just hit another selection button, drag the slider (this updates to show you what will be selected as you drag it), or enter a new selection number, and it will base it off of whatever you started with. If you want to use a different selection, select the edges you want to use and hit "Set as New Selection".


Current Features

In Sequence

Select by Number - Typing a number in the input field and hitting enter will select every nth edge, based on your selection. So if you enter "2" you will select by every 2nd edge. The slider works in a similar manner. Drag it to interactively select every nth edge. The input field will update to show you whether its every 2nd, 3rd, 4th, etc. Both the slider and the input field are currently limited to a minimum of 1 and a max of 16, and defaults to 2.

Quick Select by Number - Same as above, but with button presets. The "2" button will select every 2nd edge, the "3" every 3rd, etc. Whatever button you click will also update the Select by Number input field.

Selection Type - Determines whether the tool will select every nth edge in a ring or loop.

Current Selection

Set as New Selection - Will take whatever is currently selected, and set it as the selection to be used when performing script actions.

To Edge Ring - Will take the current selection (ignoring the initial/saved selection), and convert it to the appropriate edge ring(s). This has been included because the Right Marking Menu Edge Ring/Edge Loop Utilities work differently than the Select > Convert Selection > To Edge Loop / Ring menu commands do. If you have two edges on the same ring/loop selected, the right marking menu will only select the edge ring/loop between them, where-as the Convert Selection > To Edge Loop / Ring will select the whole thing.

To Edge Loop - Same as above, but will select the Edge Loop(s).


Currently Known Issues

Not much script commenting, warnings about selecting by every 1 do not function properly, and the script currently does not warn you if you start it with nothing selected, or if you click "Set as New Selection" with nothing selected.


Future Features

Better commenting of the script, with more warnings, etc. including implementing the currently scripted, but unused, and un-fleshed out menu bar, with information about the script, how to use it, where to find this thread, where to download it, etc.

Save Current Selection - Save the current selection to a Quick Select Set so that its available throughout the current session, and is saved with the scene, and available the next time it is loaded. These saved selections will also rapidly be able to be loaded either through a numeric input or quick select button. The reason for this feature would be that Quick Select Sets are buried in two separate menu lists, one for creating and one for retrieving.

Set as New Selection w/o having to press the button - Currently unsure of how to script this. Thinking of a script job with commands run when the Rapid Select Tool window loses focus, but unsure whether or not the script selecting stuff causes the window to lose focus, or how to handle when a user is actually selecting something they want the script to use as a new selection, and just using Maya in general.

Select in Pattern - Would have a feature to operate like the current pattern selection available in Maya, but also for pattens it doesn't seem to currently handle, for instance, select 2 edges, skip 4, repeat. I do not currently possess the scripting knowledge to implement this.


Far Future Features

All of the above, but with the option to use vertices, faces, and uv's as well. I do not currently possess the scripting knowledge to implement this.

Replies

  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Getting errors like cannot find procedure. Only edge ring and edge loop work on my end. Maya 2012 is what I tested it on. Havent looked at the code yet.
  • Illusions
    Options
    Offline / Send Message
    Illusions polycounter lvl 18
    Getting errors like cannot find procedure. Only edge ring and edge loop work on my end. Maya 2012 is what I tested it on.

    Have to put the script in your Maya scripts folder in My Documents, and call it via rapidSelectTool; after restarting Maya. If you don't want to put it in the scripts folder, load it in the Script Editor, and comment out the global proc line at the start so its like this:
    //global proc rapidSelectTool () {
    
    Then comment out the closing bracket above // Procedures. If anyone knows how to fix this, without this work around, let me know.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Yup called it like that. Just did it again...will try on 2011 at home
  • Illusions
    Options
    Offline / Send Message
    Illusions polycounter lvl 18
    Yup called it like that. Just did it again...will try on 2011 at home

    Arghh, if you can post the exact error being given I'll take a look, as I'm using Maya 2012 as well and it runs here. :poly127:

    Edit: Never mind, found how to get the errors. Running the script from the script editor, then calling rapidSelectTool; doesn't seem to produce them, but just calling the script from the command line without having previously run it via the script editor causes the non-global procedures not to be found. Trying to find a way to fix this.

    Until then, running this from the script editor should work (so at least I can get some feedback on how it works, instead of if it works :\):
    // Declare commonly used and initial variables 
    string $wnd = "rapidSelectTool_GUI";
     string $wnd_title = "R-Select";
     int $width = 180;
     int $selectionValue = 2;
     int $minAmount = 1;
     int $maxAmount = 16;
     global string $rsInitialSelection[];
     $rsInitialSelection = `ls -sl`;
      // Check if rapidSelectTool window exists, and if so, delete it
     if (`window -exists $wnd`) deleteUI -window $wnd;
      // Create the window
     window -s 0 -mxb 0 -mb 1 -t $wnd_title $wnd;
          // Create the menubar
         /* - Not yet working. Delete commenting when ready.
         menuBarLayout -w $width -h 24;
         
         menu -label "Edit" rapidSelectTool_EditMenu;
             menuItem -en 0 -label "Reset Settings" menuItem1;
             
         menu -label "Help" rapidSelectTool_HelpMenu;
             menuItem -en 0 -label "About" menuItem1;
             menuItem -en 0 -label "Script Download" menuItem2;
             menuItem -en 0 -label "Polycount Thread" menuItem3;
             menuItem -en 0 -label "Creative Crash" menuItem4;
             
         separator -h 5 -st "in";
         */
             
         // Create the controls
         
         // Select In Sequence Controls
         frameLayout -bv 1 -bs "etchedOut" -lv 1 -l "In Sequence" -mh 0 -mw 0;
         columnLayout inSequence;
              
             // Select by Number Controls
             frameLayout -bv 1 -bs "out" -lv 0 -l "Select by Number" -mh 5 -mw 5 -p inSequence -w $width;
              
             rowColumnLayout -nc 2 -cat 2 "left" 8; 
                 // Number Controls
                 text -align "left" -label "Select by Number: ";
                 intField -w 68 -minValue $minAmount -maxValue $maxAmount -v $selectionValue -s 1 -cc ("sxnValueSelect") -ec ("sxnValueSelect") sxnSelectionValue;
                 
            setParent ..;
                 // Slider Controls
                 rowLayout -nc 3;
                 text -w ($width/12 - 6) -align "center" -label $minAmount minAmountSliderBookend;
                 intSlider -w ($width/12 * 10 - 8) -minValue $minAmount -maxValue $maxAmount -v $selectionValue -s 1 -dc ("sxnSliderSelect") sxnSlider; 
                 text -w ($width/12 - 2) -align "center" -label $maxAmount maxAmountSliderBookend;
                 
             
             // Quick Select by Number Controls
             frameLayout -bv 1 -bs "out" -lv 0 -l "Quick Select by Number" -mh 5 -mw 5 -p inSequence -w $width;
                 columnLayout;
                 text -h 14 -align "left" -label "Quick Select by Number: ";
                 separator -w $width -h 3 -st "none";
                 flowLayout -w $width -h 76 -wr true;
                 button -w ($width/3 - 5) -h 36 -label "2" -command ("quickSelectByNumber " + 2);
                 button -w ($width/3 - 5) -h 36 -label "3" -command ("quickSelectByNumber " + 3);
                 button -w ($width/3 - 5) -h 36 -label "4" -command ("quickSelectByNumber " + 4);
                 button -w ($width/3 - 5) -h 36 -label "5" -command ("quickSelectByNumber " + 5);
                 button -w ($width/3 - 5) -h 36 -label "6" -command ("quickSelectByNumber " + 6);
                 button -w ($width/3 - 5) -h 36 -label "8" -command ("quickSelectByNumber " + 8);
            
            // Select by Type Controls
            frameLayout -bv 1 -bs "out" -lv 0 -l "Selection Type" -mh 5 -mw 5 -p inSequence -w $width;
                flowLayout;
                text -align "left" -label "Selection Type: ";
                radioCollection;
                    radioButton -sl -label "Ring" ringSelection;
                    radioButton -label "Loop" loopSelection;
                      
         // Current Selection Controls
         setParent $wnd;
         frameLayout -bv 1 -bs "etchedOut" -lv 1 -l "Current Selection" -mh 0 -mw 0;
         columnLayout currentSelection;
         frameLayout -bv 1 -bs "out" -lv 0 -l "Current Selection Controls" -mh 5 -mw 5 -p currentSelection -w $width;
         columnLayout -rs 3 -adj 1 ;
         button -label "Set as New Selection" -command ("$rsInitialSelection = `ls -sl`;");
         button -label "To Edge Ring" -command ("SelectEdgeRing;");
         button -label "To Edge Loop" -command ("SelectEdgeLoop;");
         
         setParent $wnd;
         
         // General Controls
         rowColumnLayout -nc 2 -cs 2 1;
         button -w ($width/2) -label "Select" -command ("makeSelection");
         button -w ($width/2) -label "Close" -command ("deleteUI " + $wnd);
         
         showWindow $wnd;
         
     // Procedures
      // Select by Number Slider Procedure
     proc sxnSliderSelect () {
         $selectionValue = `intSlider -q -v sxnSlider`; // Get the new selection value
         sxnUpdateControls ($selectionValue); // Update all controls with this new selection value
         makeSelection ();    
     }
      // Select by Number Selection Value Procedure
     proc sxnValueSelect () {
         $selectionValue = `intField -q -v sxnSelectionValue`; // Get the new selection value
         sxnUpdateControls ($selectionValue); // Update all controls with this new selection value
         makeSelection ();
     }
      // Quick Select by Number Procedure
     proc quickSelectByNumber (int $selectionValue) {
         // New selection value already passed via Quick Select by Number buttons
         // No need to query it
         sxnUpdateControls ($selectionValue); // Update all controls with this new selection value
         makeSelection ();
     }
      // Update the Select by Number Controls
     proc sxnUpdateControls (int $selectionValue) {
         intField -e -v $selectionValue sxnSelectionValue;
         intSlider -e -v $selectionValue sxnSlider;
         if ($selectionValue == 1) {
             warning "Selecting by every 1 may produce undesired results.";
         }
     }
      // Make Selection
     proc makeSelection () {
         $amount = `intField -q -v sxnSelectionValue`; // Get the amount to select by
         global string $rsInitialSelection[];
         select -r $rsInitialSelection; // Restore the saved selection
         // Determine what selection method to use (Loop or Ring)
         int $selectionType = `radioButton -q -sl loopSelection`;
         if ($selectionType == 1) {
             polySelectEdgesEveryN "edgeLoop" $amount;
         } else {
             polySelectEdgesEveryN "edgeRing" $amount;
         }
     }
     
    
    
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Sorry was on the bus back home. Just change the proc to global proc, pretty much what I do always.
    global proc sxnSliderSelect () {
    

    Also a suggestion is that instead of selecting the edge then running the script, it seems you store the selection as a global at the start instead of querying what is selected when the user clicks the appropriate command. This makes the tool more flexible then making the user switch modes or re-calling the script.

    Also at the start of the script, just check the size of the selection and filter it to edges. Solves the problem of not knowing what to do with an incorrect selection.

    Dont really think the select edge loop and ring would be useful as you can double click the edge and select the loop/ring though the skipping edges is definitely handy.
  • Illusions
    Options
    Offline / Send Message
    Illusions polycounter lvl 18
    Sorry was on the bus back home. Just change the proc to global proc, pretty much what I do always.

    I figured as much. Is there any way to keep them as local procedures?
    Also a suggestion is that instead of selecting the edge then running the script, it seems you store the selection as a global at the start instead of querying what is selected when the user clicks the appropriate command. This makes the tool more flexible then making the user switch modes or re-calling the script.

    The reason I don't query when the buttons/sliders are used is so that you can see the results of your selection, without having to undo them, or reselect things if you don't like the results. Currently the button "Set as New Selection" allows you to set a new selection for the script to base its actions off of. If the current way the script works isn't useful, I'll give it a change. I could always add the way it works currently to a checkbox.
    Also at the start of the script, just check the size of the selection and filter it to edges. Solves the problem of not knowing what to do with an incorrect selection.

    Will do.
    Dont really think the select edge loop and ring would be useful as you can double click the edge and select the loop/ring though the skipping edges is definitely handy.

    Its mainly there in case you only selected one edge, used the script, and then decided that you wanted every nth edgeloop/ring instead of just every nth edge.
Sign In or Register to comment.