X-Ray Hotkey toggle


#1

My college programmed the Alt+1 as a hotkey to toggle the x-ray on and off in Maya. They also programmed the Alt+2 as a hotkey to toggle the wireframe on shaded on and off. This was very helpful when modeling.

Now that I have my own copy of Maya, I do not have those hotkeys programmed in because it is not a Maya default. I’ve copied and pasted from the script editor this line of code:

modelEditor -e -xray 1 modelPane14;
// Result: modelPane14 //
editMenuUpdate MayaWindow|mainEditMenu;

into the hotkeys window (window>settings/preferences>hotkeys…) and set it to Alt+1. After saving, the new hotkey worked to turn the x-ray command on. I have no clue what line of code I need to make x-ray toggle on and off using just one hotkey. I’ve experimented, but my syntax is off.

What lines of code should I input into the hotkey editor to toggle x-ray on/off and wireframe on shaded on/off?


#2

Here are the commands in order

Xray On

modelEditor -e -xray 1 modelPanel1;
modelEditor -e -xray 1 modelPanel2;
modelEditor -e -xray 1 modelPanel3;
modelEditor -e -xray 1 modelPanel4;

Xray Off

modelEditor -e -xray 0 modelPanel1;
modelEditor -e -xray 0 modelPanel2;
modelEditor -e -xray 0 modelPanel3;
modelEditor -e -xray 0 modelPanel4;

Wireframe on Shaded On

modelEditor -e -wos 1 modelPanel1;
modelEditor -e -wos 1 modelPanel2;
modelEditor -e -wos 1 modelPanel3;
modelEditor -e -wos 1 modelPanel4;

Wireframe on Shaded Off

modelEditor -e -wos 0 modelPanel1;
modelEditor -e -wos 0 modelPanel2;
modelEditor -e -wos 0 modelPanel3;
modelEditor -e -wos 0 modelPanel4;

Hope this helps,
Bill


#3

Thanks! I’m gonna try it now. copies codes and runs off to Windows machine


#4

Hmm, doesn’t seem to be working. Maybe I did something wrong.

This is what I did:

Window>Settings/Preferences>Hotkeys…
Hit Button: New (hotkey)
Field: Name: xray_toggle
Field: Command:
modelEditor -e -xray 1 modelPanel1;
modelEditor -e -xray 1 modelPanel2;
modelEditor -e -xray 1 modelPanel3;
modelEditor -e -xray 1 modelPanel4;
modelEditor -e -xray 0 modelPanel1;
modelEditor -e -xray 0 modelPanel2;
modelEditor -e -xray 0 modelPanel3;
modelEditor -e -xray 0 modelPanel4;
Hit Button: Accept
Assign new hotkey
Assigned Alt+1
Hit Button: Assign
Hit Button: Save

Then when I try the hotkey, I get the error:
Error:Object not found: modelPanel


#5

Okay, I deleted the few xray and wireframe on shaded hotkey attempts and tried making a new hotkey again.

This time I didn’t get an error, but I didn’t get results, either. I hit the new hotkey and Maya said: Result: modelPanel4
But the scene didn’t turn x-ray.:cry::banghead:


#6

use this in the hotkey editor… don’t have one for the wireframe on/off shader

if (getPanel -to (eval("getPanel -withFocus"))) {
$currentPanel = getPanel -withFocus;
if (modelEditor -q -xray $currentPanel) {
modelEditor -edit -xray 0 $currentPanel;
} else {
modelEditor -edit -xray 1 $currentPanel;}
};

[size=2]
[/size]


#7

Thank you! The code worked!

From seeing the other preexisting toggle codes in the hotkey window, I had a feeling that the code I needed would be one of those complicated ones with a couple of ‘ifs’ in it, too.

Thanks again.

EDIT: I just found out the code for toggling wireframe on shaded. It’s the same as the code you gave to me, only -xray is replaced with -wos. So the code would read like this:

if (getPanel -to (eval("getPanel -withFocus"))) {
$currentPanel = getPanel -withFocus;
if (modelEditor -q -wos $currentPanel) {
modelEditor -edit -wos 0 $currentPanel;
} else {
modelEditor -edit -wos 1 $currentPanel;}
};


#8

I was just trying to figure out the wireframe on shaded thing I was searching for the whole phrase instead of wos in the hot key editor.

thanks koogle and donky.


#9

Here’s what I’m using currently

For x ray:

string $panel = getPanel -wf;
modelEditor -e -xray ( !modelEditor -q -xray $panel ) $panel;

            and for wireframe on shaded:

string $aaa = getPanel -wf ;
modelEditor -e -wos (!modelEditor -q -wos $aaa) $aaa;


#10

It’s Donyk.:stuck_out_tongue:


#11

Thanks everyone, I was looking to do just this and it’s helped out a lot.


#12

Thanks for the script. I was wondering why the heck this command wasn’t in the hotkey editor. I tried to alter the wireframe display script to no evail before I searche dthe forums. Man I need to learn more MEL!


#13

here’s a slightly more involved version - this one checks to make sure your focus is on a modelPanel

string $panel = `getPanel -wf`;
 if ( `modelEditor -ex $panel` )
 	modelEditor -e -xray ( !`modelEditor -q -xray $panel` ) $panel;

the same will work with the wireframe on shaded command.

-sunit


#14

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.