View Full Version : newb question on toggles
cgbeige 08-03-2009, 06:11 PM how would I change this to be a toggle for the respective "off/0" parts:
string $mySelection[] = `ls -sl`;
for($each in $mySelection) { // each is a new variable that is made equal to one of the array of selected objects.
setAttr ($each + ".overrideEnabled" ) 1;
setAttr ($each + ".overrideShading" ) 0;
setAttr ($each + ".overrideTexturing" ) 0;
}
|
|
In your for loop, use getAttr to find out if it's currently on or off, then use an if to switch it accordingly.
i.e.
if(`getAttr ($each+".overrideEnabled")`){
setAttr ($each+".overrideEnabled") 0 ;
}
else {
setAttr ($each+".overrideEnabled") 1 ;
}
cgbeige
08-04-2009, 01:07 AM
sorry, this is giving me syntax errors:
string $mySelection[] = `ls -sl`;
for($each in $mySelection) { // each is a new variable that is made equal to one of the array of selected objects.
if(`getAttr ($each+".overrideEnabled)`){
setAttr ($each+".overrideEnabled) 0 ;
}
else {
setAttr ($each+".overrideEnabled) 1 ;
}
if(`getAttr ($each+".overrideShading)`){
setAttr ($each+".overrideShading) 0 ;
}
else {
setAttr ($each+".overrideShading) 1 ;
}
if(`getAttr ($each+".overrideTexturing)`){
setAttr ($each+".overrideTexturing) 0 ;
}
else {
setAttr ($each+".overrideShading) 1 ;
}
It's probably something simple but I'm winging it here.
Add a quote after the attribute name, forgot it in my example..sorry.
($each+".attributeName")
Make sense?
cgbeige
08-04-2009, 04:08 AM
still bad
// Error: else { //
// Error: Syntax error //
// Error: } //
// Error: Syntax error //
// Error: } //
// Error: Syntax error //
// Error: } //
// Error: Syntax error //
// Error: } //
// Error: Syntax error //
// Error: }; //
// Error: Syntax error //
string $mySelection[] = `ls -sl`;
for($each in $mySelection){
setAttr ($each+".overrideEnabled") 0 ;
}
else {
setAttr ($each+".overrideEnabled") 1 ;
}
if(`getAttr ($each+".overrideShading")`){
setAttr ($each+".overrideShading") 0 ;
}
else {
setAttr ($each+".overrideShading") 1 ;
}
if(`getAttr ($each+".overrideTexturing")`){
setAttr ($each+".overrideTexturing") 0 ;
}
else {
setAttr ($each+".overrideShading") 1 ;
}
Ah ya just forgot the if statement on the first one, all good.
Below tested and works.
string $mySelection[] = `ls -sl`;
for($each in $mySelection){
if(`getAttr ($each+".overrideEnabled")`){
setAttr ($each+".overrideEnabled") 0 ;
}
else {
setAttr ($each+".overrideEnabled") 1 ;
}
if(`getAttr ($each+".overrideShading")`){
setAttr ($each+".overrideShading") 0 ;
}
else {
setAttr ($each+".overrideShading") 1 ;
}
if(`getAttr ($each+".overrideTexturing")`){
setAttr ($each+".overrideTexturing") 0 ;
}
else {
setAttr ($each+".overrideShading") 1 ;
}
}
cgbeige
08-04-2009, 05:15 PM
works great - thanks. This is a big help
No prob. This same method obviously works for any attribute. You can hard code it and make a button or put it in a procedure and pass in the attributes, etc.
safakoner
08-04-2009, 11:22 PM
small addition...
string $mySelection[] = `ls -sl`;
int $val;
for($each in $mySelection)
{
$val = `getAttr ($each + ".overrideEnabled")`;
setAttr ($each + ".overrideEnabled") (!$val) ;
/*
etc.
*/
}
Ah sweet, that is way easier than my answer. =)
Good call safakoner.
CGTalk Moderation
08-05-2009, 04:37 PM
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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.