checkbox and eval?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2011
checkbox and eval?

I need to figure out a way to get checkboxes not to stop my script from loading if the attributes they connect to don't exist yet. I'm guessing this is done with eval but how does that get factored into the checkbox code?:

			menu -label "RT" -tearOff false;
				menuItem
					-label "Displacement"
					-postMenuCommand "getAttr vraySettings.rt_displacement"
					-ann "Toggle Displacement for RT"
					-c "setAttr vraySettings.rt_displacement (!(`getAttr vraySettings.rt_displacement`))"
					-checkBox (`getAttr vraySettings.rt_displacement`);
				menuItem
					-label "Subdivision"
					-postMenuCommand "getAttr vraySettings.rt_subdivision"
					-ann "Toggle Subdivision Rendering for RT"
					-c "setAttr vraySettings.rt_subdivision (!(`getAttr vraySettings.rt_subdivision`))"
					-checkBox (`getAttr vraySettings.rt_subdivision`);
				menuItem
					-label "Proxies"
					-postMenuCommand "getAttr vraySettings.rt_vrayProxyObjects"
					-ann "Toggle Proxy Rendering for RT"
					-c "setAttr vraySettings.rt_vrayProxyObjects (!(`getAttr vraySettings.rt_vrayProxyObjects`))"
					-checkBox (`getAttr vraySettings.rt_vrayProxyObjects`);
				
				menuItem -sm true
					-postMenuCommand "getAttr vraySettings.rt_engineType"
					-label "RT Mode";
				menuItem -label "GPU"
					-c "setAttr vraySettings.rt_engineType (!(`getAttr vraySettings.rt_engineType`))"
					-checkBox (`getAttr vraySettings.rt_engineType`);
 
  03 March 2011
add in some objExists/attributeExists calls to your menu commands.
 
  03 March 2011
can you have if (objExists ) stuff in menu commands? Could you post some example code?
 
  03 March 2011
a menu command is really nothing more than a block of MEL code, so you can do literally anything inside it. However, menuItems with checkboxes or radio buttons are slightly more complicated than this because once a menuItem is created it is static, and does not update (automatically!). The -cb and -rb flags are only significant on initial creation of the menuItem. This means that when you create the menuItem the checkbox will accurately reflect the attribute status, but it will never change/update unless you change it manually. If, for example, the user changes the attribute manually on the node your menuItem will be out of sync.
The best way around this is to use the menu -pmc flag when you create the menu. This defers the building of the menuItems to a global proc, which is called every time the menu is about to be opened. In this proc you can put as much `objExists` and attribute checking as you like.

global proc buildTestMenu()
{
	menu -e -dai testMenuName;    // EMPTY the menu!
	setParent -m testMenuName;

	int $isPersp = `objExists persp`;
	int $isCam1 = `objExists camera1`;

	int $pVis = ($isPersp) ? `getAttr persp.visibility` : 0 ;
	int $cVis = ($isCam1) ? `getAttr camera1.visibility` : 0 ;

	menuItem -en $isPersp -l "persp visible?" -cb $pVis;
	menuItem -en $isCam1 -l "camera1 visible?" -cb $cVis;
}

{
global string $gMainWindow;
setParent $gMainWindow;

menu -l "test Menu" -p $gMainWindow -pmc "buildTestMenu" testMenuName;
setParent -m ..;
}

:nathaN

Last edited by NaughtyNathan : 03 March 2011 at 09:15 PM.
 
  04 April 2011
awesome - thanks again, Nathan.
 
  04 April 2011
hey Nathan,

I'm just getting into trying to incorporate this into my script and I'm wondering if you can explain the syntax here:

	int $pVis = ($isPersp) ? `getAttr persp.visibility` : 0 ;
	int $cVis = ($isCam1) ? `getAttr camera1.visibility` : 0 ;


I'm not clear on the ? and : usage.
 
  04 April 2011
ah, sure.. this is just a natty shortcut trick that allows you to do an if..else condition as a single line, rather than several.

this should explain it better than I could:

http://download.autodesk.com/us/may...pt_operator.htm

:nathaN
 
  04 April 2011
ah okay thx
 
  04 April 2011
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:47 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.