Toggle image plane visibility?

Hello mel guru, or any other mel users...
I was wondering how I could get the image to toggle between the position "none" to "Rgb"..
I understand the principle stuff..like I have to get the current window then the image plane but how can i check to see if the current camera as an image plane and if yes it make its visibility to none or Rgb...
I'm almost there but stuck..
someone can help.?

cheers and thanks for all

To list Image planes connected to camera - perspSHape should be your camera shape node:
listConnections -source 1 -type imagePlane perspShape;

To set display mode to none:
setAttr imagePlane1.displayMode 0;

To set display mode to none:
setAttr imagePlane1.displayMode 2;

hope it helps

thanks a lot I'll try to go with that if I can figure out the rest..

many thanks

well thanks but I guess I'm still stuck cause I don't know how to use that..it seems that the listSelection only list it but to use the setAttr I need to select it don't I..?
(I know I suck in mel)..progrmming really isn't my stuff..but I understand the need of learning so that's what I'm doing..

thanks a lot for the help.

I don't know if you have a specific use for the imageplane, but theMaya UI is often quicker with a texturemapped plane parented under the camera - and this would be easily hidden/unhidden....

just an idea

Here is a mel I wrote to do just that:
//Start mel script code
//==========================
/* Image Plane Toggle


Toggles the visibility of all Image Planes in your scene


Any bugs or problems, send them to
mhovland@midwaygames.com


*/
//Start of IP_Toggle Script

global proc mh_IP_Toggle()
{
// INTERFACE STUFF//
//kill the window if it exists already

if (window -exists iptWindow)
{
deleteUI -window iptWindow;
}

//define the window

string $iptWin = window
-title "Image Plane Toggle"
-widthHeight 210 105
-tlc 150 150
-sizeable false
iptWindow
;

//column layout for the window							

columnLayout;

//define some buttons							

button
-label "Hide Image Planes"
-width 200
-height 25
-command "hideEm"
hideBtn;

button
-label "Show Image Planes"
-width 200
-height 25
-command "showEm"
showBtn;

//END INTERFACE STUFF//

showWindow $iptWin;
}

//Some procedures for the buttons to do
global proc hideEm()
{
string $ipHideIndex;
string $ipHideVar[] = ls -type imagePlane;

if (size($ipHideVar) == 0)

	error ("==No Image Planes in your Scene==");


	for ($ipHideIndex in $ipHideVar) 
	{ 
		setAttr ($ipHideIndex+".displayMode") 0; 
	} 
}

global proc showEm()
{
string $ipShowIndex;
string $ipShowVar[] = ls -type imagePlane;

if (size($ipShowVar) == 0)

	error ("==No Image Planes in your Scene==");



	for ($ipShowIndex in $ipShowVar) 
	{ 

		setAttr ($ipShowIndex+".displayMode") 3; 
	}

}
//End button procedures

//================================
//end mel script code

This is one of my first scripts with an interface, so it may not be the best implimentation, but it works just fine.

Use it all you want, if you make adjustments to it, send them back my way.

Enjoy,

Ok I wasn't expected that much..but this is great I'm gonna start looking at it to figure some stuff out ..

thanks a lot guys..

Ok thanks to you guys i understood few thing,
now I went quickly to make my toogle
and i end up with that..
_________________________________
string $ipHideIndex;
string $ipHideVar[] = ls -type imagePlane;

if (size($ipHideVar) == 0)

error ("==No Image Planes in your Scene==");

for ($ipHideIndex in $ipHideVar)
{
if ($ipHideIndex+"diplayMode" ==3)
{
setAttr ($ipHideIndex+".displayMode") 0;
}
else
{
setAttr ($ipHideIndex+".displayMode") 3;
}
}
_______________________________________

So it worked but ONLY THE FIRST TIME I USED IT !!!!

now I don't get it, it doesn't work at all anymore but doesn't do any errors...so a little help again if you can

thanks so much, I'm learnig a lot

i dont know if its a help... but generally i specify the rendering camera from the start and call it renCamera... which means that i can capture a command from the script editor and create a hot key for it...

in the past ive made a toggle alpha (of image plane) with a seperate 50% alpha switch which would allow for semi trans view...

its hardly code but its quicker than sourcing a script...

thanks for the tip, but I was very curious about the particular problem I have in the above post...

anyone ???

thanks anyway everybody

cheers

cant directly read/write attributes with MEL scripting, you mostly can in the context of an expression node however.

so you gotta collect the attribute value for comparison:

if (getAttr ($node+".attri") == x)

not sure why your syntax was parsed, but that it was meant that it would do the else... even tho it lacks the capacity to resolve whether the conditional ever were true. dunno.

Ok thanks a lot I'll try that...
Still it's weird for me that it only works once...

cheers

Ok I tried,
It works great thanks a lot here's the code in case somebody is intrested...
________________________________________

global proc hideImagePlane()
{
string $ipHideIndex;
string $ipHideVar[] = ls -type imagePlane;

if (size($ipHideVar) == 0)

error ("==No Image Planes in your Scene==");

for ($ipHideIndex in $ipHideVar)
{
if (getAttr ($ipHideIndex+".displayMode")==3)
{
setAttr ($ipHideIndex+".displayMode") 0;
}
else if (getAttr ($ipHideIndex+".displayMode")==0)
{
setAttr ($ipHideIndex+".displayMode") 3;
}
}
};
__________________________________________

thanks so much everybody..

cheers

This is the command I have for my hotKey:

$currentPanel = getPanel -withFocus;
$state = modelEditor -q -cameras $currentPanel;
modelEditor -edit -cameras (!$state) $currentPanel;

I found it somewhere. The interesting part it the $state. I found it really elegant, if 0 make it 1, if 1 make it 0. I used it for all my model panel hotkeys, wireframe on shaded, xray, etc.

You could use it in your proc if you query .visibility instead of .displayMode. That is what the -cameras flag above is doing. The attribute needs to be a boolean, 0 or 1.