Remove selected items form textScrollList

Hi you all I am stuck in a small issue with a mell script.

I made just for exercise a small script that load objects selected from the viewport in a textScrollList and rename it.
I would be able to remove some items aready loaded in the list selecting them from the textScrollList (i was able to do that) and use a procedure to remove them from the textScrollList.
some of you nice people has some good advice for a newbie? I hope you can hel me. Here follow the code I am using so far and that works until this critical point.

Cheers
Francesco

// Procedure to create the UI

global proc makeUI ()
{
if (window -exists myRenameUI)
    deleteUI myRenameUI;

windowPref -r myRenameUI;
window -title "Rename Those Items" -w 300 -h 550 -sizeable off myRenameUI;

columnLayout -adj off renameCol;
    // here I allow the multi selection on the textScrollList
textScrollList -height 300 -width 300 -allowMultiSelection on toRenameTSL;
button -label "Get Items" -width 300 -c getItems getButton;
button -label "Clear All" -width 300 -c clearAllProc clearAll;
button -label "remove Selected" -width 300 -c clearSelectedProc clearSelected;
textField -width 500 -it "insert new name" newNameTF;
button -label "Rename" -width 300 -c renameThis renameButton;
showWindow myRenameUI;
}

// Procedure to load the objects selected in the scene in the textScrollList

global proc getItems ()
{
textScrollList -e -removeAll toRenameTSL;
string $objInScene[] = ls -sl;
print $objInScene;
for ($eachObj in $objInScene)
    {
    textScrollList -e -append $eachObj toRenameTSL;
    }
}

// Procedure to perform the renaming

global proc renameThis()
{
string $objToRename[] = textScrollList -q -allItems toRenameTSL;
string $newName=textField -q -text newNameTF;
for ($eachObjToRename in $objToRename)
    {
    rename $eachObjToRename ($newName + "_#");
    }
}

// Procedure to clear the content of the textScrollList
//(useless, i know, just practicing with commands and flags)

global proc clearAllProc()
{
textScrollList -e -removeAll toRenameTSL;
}

// !!! Here there is !!! //
// that was my idea: create a procedure that is suppose to:
//    - read the selection
//    - cast the strings in an array
//    - perform a FOR...IN loop based on the array content to remove the items from the textScrollList
//
//Please notice: every other more efficent solution is more than welcome

global proc clearSelectedProc()
{
//this print just the number of item selected from the scroll list
int $testVar=textScrollList -q -numberOfSelectedItems toRenameTSL;
print $testVar;
}

Wouldnt be easier to use a outliner instead? Well heres the questions aswer. The question and approach is a bit  broken tough. Additionaly you have a number of oher problems in thre.

// slightly bad advice but does what you ask.
global proc clearSelectedProc()
{
  // mel is sometimes a bit unintuitive in that querries work despite
  // the flags function by querring whatever the flag sets.
  int $selectedItems[] = `textScrollList -q -sii  toRenameTSL`;
 
  // must iterate backwards
  int $noSelected = size($selectedItems)-1;
  for ($i = $noSelected; $i>=0; $i--)
  {
   textScrollList -e -removeIndexedItem  $selectedItems[$i] toRenameTSL;
  }
}

Thank so much...I'll try asap :slight_smile:

Thank you for the tip.

Cheers
Francesco

Well to be honest my primary concern is not the way you did the script but rather why you need the script in first place. I mean to get it working you need to:

select objects
check they are the objects you want
deselect the ones you don't want
and run the script.

But see there's may not be any added value here, since you already have to do the selection. You can do that it the outliner that was already made. And mass renaming exists in the default maya GUI. So your doing a pretty big construct so that user can get one extra dialog and 3 more buttons to push to accomplish user nor needing to type _1 in the quick rename box that's built in.

So yes the script may be doing something but why would anyone except you want to use it? So either you need to remove some functionality form the script to make it more streamlined OR you need something more to make it usable.

Please dont get offended. Im just saying that the general approach may be a bit obsolete. So you may want to reconsider your approach.

PS: the best GUI is one that has no buttons, dialogs or anything. It just magically happens. Sadly if we knew how to do theese in big degrees wed be obsolete.