Tutorials at Lizard Lounge Graphics : Maya - toggle x-ray script

I wanted a simple way to toggle x-ray shading in all of my modeling panels in Maya. There is a little script that will add something like the following to your hotKeys, but it only affects the current panel based on its focus.

This script changes all the visible modeling panels to x-ray shading and has been tested and under Maya v6.0.1.

To use, open your Window-Preferences-Hotkeys and create a new entry under the Display category. Call it something like "toggleXrayShading" and paste the following code into the command window. I use "alt-x" as my keyboard shortcut to use this.

A special thanks goes to Björn Deronde for making this nifty icon to go with this script. Thanks, Björn!

Read the fine print before you use this.

// Toggle Xray
//
string $visPanel[]=`getPanel -vis`;
int $mode;
if (size($visPanel)>0)
{
  for ($panel in $visPanel)
  {
    if (`match "^modelPanel" $panel`=="modelPanel")
    {
      $mode=`modelEditor -q -xray $panel`;
      if ($mode>0)
        modelEditor -e -xray 0 $panel;
      else
        modelEditor -e -xray 1 $panel;
    }
  }
 print ("\nxray="+$mode+".");
} else
 print ("\nNo model panels to modify.");