XRay for Maya

Often we require to look through an object in viewport. Here is a simple script that toggles xray property of an object.

//XRay Toggle utility tools.//
//Paste this code in a text file and rename it to xray_toggle.mel
//Copy xray_toggle.mel file to your Script folder (..\user\My Documents\maya\8.5\scripts)//
//put this line in your shelf "xray_toggle" as a button //
//Either use Button or Hotkey Ctrl+Alt+x //
global proc xray_toggle()
{

int $temp[];

string $obj_selected[]=`ls -sl`;
if ($obj_selected[0]=="")
{
error "Toggle X-ray : Select an object";
}

for ($i=0; $i<size($obj_selected); $i++)
{
$temp = `displaySurface -q -xRay $obj_selected[$i]`;

if ($temp[0]==1)
{
displaySurface -x 0 $obj_selected[$i];
print ("Toggle X-ray : X-ray property of "+$obj_selected[$i]+" removed successfully\n");
}
else
{
displaySurface -x 1 $obj_selected[$i];
print ("X-ray : X-ray property of "+$obj_selected[$i]+" activated successfully\n");
}

}

}

global proc string get_hkey()
{
string $prev_assig = `hotkeyCheck -k x -alt -ctl`;
return $prev_assig;
}

global proc set_hkey()
{
string $get_hkey = get_hkey();
if($get_hkey=="")
{
nameCommand
-ann "X-ray Toggle : Select an object "
-command "xray_toggle"
Object_xray;
hotkey -altModifier -ctl -keyShortcut "x" -name "Object_xray";
}
}

Tested on MAYA 8.5.

~ by Vikram Sharma on Nov 14, 2008.

Leave a Reply