# Mel to batch set attribute

**URL:** https://forum.highend3d.com/t/mel-to-batch-set-attribute/6968
**Category:** Maya
**Tags:** mel
**Created:** [August 16, 2001, 6:24pm UTC](https://forum.highend3d.com/t/mel-to-batch-set-attribute/6968 "2001-08-16T18:24:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nonquad](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@nonquad](https://forum.highend3d.com/u/nonquad)
#### Post date: [August 16, 2001, 6:24pm UTC](https://forum.highend3d.com/t/mel-to-batch-set-attribute/6968/1 "2001-08-16T18:24:16Z")

</div>

hi,  
I need to change the 'primary visibility' and 'visible in refractions' on 100's of simillar objects for a render...then set them all back for another render...the script editor shows:  
select -r big\_high\_group16|big\_high\_nurbsSphere140 ;  
setAttr "big\_high\_group16|big\_high\_nurbsSphere140|big\_high\_nurbsSphereShape140.primaryVisibility" 0;  
setAttr "big\_high\_group16|big\_high\_nurbsSphere140|big\_high\_nurbsSphereShape140.visibleInRefractions" 0;

I can grock the setAttr part...but I'm not familliar enough with mel to write a script that will loop through all the objects and change these attributes...then back again....

is there an exsisting script that will do this (or one that I'd be able to modify)...or a way to select a bunch of objects and change an attribute for ALL of them at once?

thanks for any help.

Michael Goldfarb

---

<div class="post-metadata">

### Author: ![tjgalda](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/t/ecd19e/32.png) [@tjgalda](https://forum.highend3d.com/u/tjgalda)
#### Post date: [August 16, 2001, 10:49pm UTC](https://forum.highend3d.com/t/mel-to-batch-set-attribute/6968/2 "2001-08-16T22:49:20Z")

</div>

here's a simple script that will do it. it is written to toggle the modes from 0 to 1 if they're at 0, or vice versa. i wrote it so that whatever is selected will be effected, so select whatever you want then run this:

string $temp[] = `ls -sl -l`;  
string $thing;  
for ($thing in $temp)  
 {  
 string $pvis = ($thing + ".primaryVisibility");  
 string $visR = ($thing + ".visibleInRefractions");

int $temp\_flag = 0;  
$temp\_flag = `getAttr $pvis`;  
if ($temp\_flag == 1)  
 {  
 setAttr $pvis 0;  
 setAttr $visR 0;  
}  
else  
 {   
 setAttr $pvis 1;  
 setAttr $visR 1;  
 }   
}

/////////////end

cheers,

> [@](#):
>
> In reply to:   
> hi,  
> I need to change the 'primary visibility' and 'visible in refractions' on 100's of simillar objects for a render...then set them all back for another render...the script editor shows:  
> select -r big\_high\_group16|big\_high\_nurbsSphere140 ;  
> setAttr "big\_high\_group16|big\_high\_nurbsSphere140|big\_high\_nurbsSphereShape140.primaryVisibility" 0;  
> setAttr "big\_high\_group16|big\_high\_nurbsSphere140|big\_high\_nurbsSphereShape140.visibleInRefractions" 0;
> 
> I can grock the setAttr part...but I'm not familliar enough with mel to write a script that will loop through all the objects and change these attributes...then back again....
> 
> is there an exsisting script that will do this (or one that I'd be able to modify)...or a way to select a bunch of objects and change an attribute for ALL of them at once?
> 
> thanks for any help.
> 
> Michael Goldfarb

TJ Galda   
Character Technical Director and Animator  
Nelvana [http://www.nelvana.com]

---

<div class="post-metadata">

### Author: ![nonquad](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@nonquad](https://forum.highend3d.com/u/nonquad)
#### Post date: [August 17, 2001, 12:21am UTC](https://forum.highend3d.com/t/mel-to-batch-set-attribute/6968/3 "2001-08-17T00:21:42Z")

</div>

go Canada! ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/smile.gif)

thanks very much!

Michael Goldfarb

> [@](#):
>
> In reply to:   
> here's a simple script that will do it. it is written to toggle the modes from 0 to 1 if they're at 0, or vice versa. i wrote it so that whatever is selected will be effected, so select whatever you want then run this:
> 
> string $temp[] = `ls -sl -l`;  
> string $thing;  
> for ($thing in $temp)  
> {  
> string $pvis = ($thing + ".primaryVisibility");  
> string $visR = ($thing + ".visibleInRefractions");
> 
> int $temp\_flag = 0;  
> $temp\_flag = `getAttr $pvis`;  
> if ($temp\_flag == 1)  
> {  
> setAttr $pvis 0;  
> setAttr $visR 0;  
> }  
> else  
> {   
> setAttr $pvis 1;  
> setAttr $visR 1;  
> }   
> }
> 
> /////////////end
> 
> cheers,
> 
> TJ Galda   
> Character Technical Director and Animator  
> Nelvana [http://www.nelvana.com]
