Checking status of viewport variable via python...

Checking status of viewport variable via python...

Anonymous
Not applicable
1,201 Views
2 Replies
Message 1 of 3

Checking status of viewport variable via python...

Anonymous
Not applicable

Hi All! I am a python/maya programming n00b, (mostly stay on the art side of things) but I'm needing to write a script to make my life a little easier for a project I'm working on. Currently I have a script that calls these items:

cmds.modelEditor("modelPanel1", edit=True, grid=0);
cmds.modelEditor("modelPanel2", edit=True, grid=0);
cmds.modelEditor("modelPanel3", edit=True, grid=0);

This simply turns off the grid in the given viewports. Works great. But what I would like to do is have it "check" said viewports and simply invert the state it's currently in. So if the grid is turned off, it turns it on. If it's on, it turns it off. I know I should use the "if" functions, but what I'm not clear on is what syntax to use to query the state of the grid/on off via python in Maya? Thanks for any help!

0 Likes
Accepted solutions (1)
1,202 Views
2 Replies
Replies (2)
Message 2 of 3

stuzzz
Collaborator
Collaborator
Accepted solution

You can have a toggle mimic just by querying the current value then to invert it with "not".

 

cmds.modelEditor("modelPanel1", edit=True, grid=not cmds.modelEditor("modelPanel1", q=True, grid=True))

 

0 Likes
Message 3 of 3

Anonymous
Not applicable

That worked! Thanks for the help!