Show > Isolate Select > View Selected

Hi, I don't come on here much but I'm pretty stuck on something.
During a project I am doing lately I am finding that I am using the Show > Isolate Select > View Selected command alot. Now I want it as a shelf icon, looking in the hotkep editor the command to turn it on is this :

CODE
{  
string $currentPanel = getPanel -withFocus;  
string $panelType = getPanel -to $currentPanel;  
if
($panelType ==  "modelPanel") {   if (size(ls -sl) > 0)
{ enableIsolateSelect $currentPanel true;    }
else
{ enableIsolateSelect $currentPanel false;     }  }}

To make my Turn off Isolate selection all I did was changed the true to false and in the following line changed the false to true.

CODE
{  
string $currentPanel = getPanel -withFocus;  
string $panelType = getPanel -to $currentPanel;  
if
($panelType ==  "modelPanel") {   if (size(ls -sl) > 0)
{ enableIsolateSelect $currentPanel false;    }
else
{ enableIsolateSelect $currentPanel true;     }  }}

So now I have 2 buttons, 1 for switching it on and 1 for switching it off, now........ is there a way I can merge the 2 scripts to make 1 toggle button instead of 2 buttons (on/off)?

Regards
Mick

Hi...

Hope you did'nt search well before u posted u query! Anyway this is the code, just you have to enquire the "isolateSelect state".

string $curentPanel = paneLayout -q -pane1 viewPanes;
int$x = isolateSelect -q -state $curentPanel;
if ($x == 0)
enableIsolateSelect $curentPanel 1;
else
enableIsolateSelect $curentPanel 0;

rgds
PREM

Hi PREM, thanks for your input, I tried the script, and it works if you have a single view up, but if you have 2 or more viewports up it seems to always affect the top view and not the selected port.

I did do a search for what I was looking for, unfortunately I only did a search for view selected but it gave over 1000 results and my eyes went blurred at around 300 or so, lol. It didn't even occur to me to do a search for enableIsolateSelect, it gave me 5 results.

CODE
{
string $panel = getPanel -withFocus;
if ( isolateSelect -q -state $panel == 0 )
    enableIsolateSelect $panel 1;
else
    enableIsolateSelect $panel 0;
}

This seems to do the trick. Here's the link to the original post

Toggle Question, can't get a simple toggle to work...

I have also changed my topic title to try and make it easier for people who have the same question.
Thanks again PREM

Regards
Mick

Excuse me, does anyone know a way to update the shelf icon? This would be great for toggle commands.

thanks!

QUOTE(lxdengar @ 09/12/07, 10:00 AM) [snapback]273187[/snapback]
Excuse me, does anyone know a way to update the shelf icon? This would be great for toggle commands.

thanks!

shelf icons (buttons) are regular MEL/ELF controls and as such can be queried and edited in a number of ways. However, to edit a control you need to know it's name and Maya assigns shelf button names dynamically on creation so there's no way to predict what it will be called. You would have to embed some identifying sting into the shelf button in a place where you knew it would be preserved (inside the edit command would be the most obvious place)
you would then have to write a procedure that the shelf button would call that searched every shelf button for the correct identifying string, thus finding out the control name when it had found the identifier.

here's a psuedo-code example:

your shelf button command would be:
CODE
// grid_icon_toggle_ident:ON:gridOn.bmp
// grid_icon_toggle_ident:OFF:gridOff.bmp

myShelfIconSwitcher "grid -toggle" grid -q -toggle "grid_icon_toggle_ident"

you would then write a script that went something like this:
CODE
global proc myShelfIconSwitcher(string $cmd,int $on, string $ident)
{
    get a list of every shelf
    loop through each shelf
        get a list of each button on the shelf
        loop through each button
            query the button command
            is the first line in button command == ("//"+$ident+"*")?
                if so, execute the $cmd with the $on value
                set the shelf icon to the icon listed on ident line $on
}

of course this is a gross simplification, you'd have to do a lot of matching and tokenizing and such, and I've probably got the on/off icons the wrong way round but hopefully you'll get the idea...

However, I don't know if this would really be as useful and helpful as you imagine as it'd be practically impossible to keep track of other events in Maya that could change the status of your toggle and besides, Maya has more than one viewport, and you can toggle the grid (for example) off in one viewport and not in the others... I personally think this whole idea is a bit of a red-herring but hey, you did ask and it perked my interested curiosity..

:nathaN

They have changed maya so that this can be done easier. You can give the shelfbutton a exlicit name at creation nowadays (as maya saves the name).

CODE
setParent MayaWindow|mayaMainWindowForm|formLayout2|formLayout14|formLayout15|formLayout49|ShelfLayout|Curves;
shelfButton -i "commandButton.xpm" -c "updateButton(\"myTestButton\")"  myTestButton;
// better chek it does not exist when you create it!

proc updateButton(string $what){
$img=shelfButton -q -i $what;
if ($img=="commandButton.xpm")
   shelfButton -e -i "sphere.xpm" $what;
else
   shelfButton -e -i "commandButton.xpm" $what;
}

off course f you wished to be very savy and vary very vain you could make a scriptjob to watch panel change and update the button then too. And the keyboard shortcut and the menuitem.

I did a script handling the isolation for all windows, and objects.
Just assign it to a shortcut and you are going.

http://www.highend3d.com/maya/downloads/me...ction-4355.html