PDA

View Full Version : on/off toggle


calinabris
11-02-2012, 01:26 AM
Hello, I need help making an on/off toggle to some script; I do not have much experience with programming and I keep getting syntax errors.

I found this script in an old post that is now locked.

toggleSurfaceBackfaceCulling();

and the person made a reply on how to toggle it ( putting this in is where I'm getting an error.

great +]

this command is a toggle > press , to switch on, press again , to switch off ...

H2o-KiD
11-05-2012, 06:45 AM
Hi, sorry for the late reply. Here's the script to toggle backface culling.

string $modelPanel = `getPanel -withFocus`;
if (`gmatch $modelPanel "modelPanel*"`)
{
if (`modelEditor -query -backfaceCulling $modelPanel`)
{
modelEditor -edit -backfaceCulling 0 $modelPanel;
}
else
{
modelEditor -edit -backfaceCulling 1 $modelPanel;
}
}

Basically, how the script works is to get modeling panel that is in focus for example "persp", then apply backface culling to the panel itself. To make it able to toggle, very simple, just ask the modeling panel whether backFaceCulling is ON or OFF (maya mel command has this ability) and if ON, turn it off and vice versa.

NaughtyNathan
11-05-2012, 11:14 AM
you can also use NOT ! for toggling which makes things slightly simpler and does away with excess if..else branches

string $modelPanel = `getPanel -withFocus`;
if (`gmatch $modelPanel "modelPanel*"`)
modelEditor -edit -backfaceCulling (!`modelEditor -query -backfaceCulling $modelPanel`) $modelPanel;

H2o-KiD
11-05-2012, 01:04 PM
Thanks for the insight Nathan! :thumbsup:

calinabris
11-06-2012, 02:05 AM
thanks for the replies.

CGTalk Moderation
11-06-2012, 02:05 AM
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.