View Full Version : Changing objects in an array
shazam 11-04-2002, 11:04 PM Hi everyone. I've got a quick MELscript question. I'm working on a project for a class and would just like to know how I could change an attribute (or multiple attributes) of all objects in an array. For example, my script is going through and looking for all the cameras in a scene, and putting them into the array. How could I change, say, the film gate on all the cameras in the array? Thanks!
|
|
empleh
11-04-2002, 11:35 PM
A "for" loop.
How do you have the camera's stored in an array? By name?
artifish
11-04-2002, 11:37 PM
loop through all the elements in the array and perform the action you want to do - here a quick example to change the focal length to 100.0 (haven't tested it, but you'll get the idea)
string $cameraArray[] =`listCameras`;
string $camera;
for ($camera in $cameraArray)
{
camera -e -focalLength 100.0 $camera;
// or
// setAttr ($camera+".focalLength") 100.0;
}
shazam
11-05-2002, 04:38 AM
I have them in the array by name.
shazam
11-05-2002, 03:41 PM
thank you very much for your help! i have a follow-up question. how would i pass values from option menus to the cameras in the array? i've tried to find out how to do this from the help but all my efforst have proved unsuccessful. i have an interface with an option menu that lists all the film gate settings such as "User," "16 mm Theatrical," etc. I have others but I'm just using this as an example. At the bottom is a button. When the user clicks on the button, I would like for the values in all my fields to be applied to the cameras.
artifish
11-05-2002, 03:48 PM
please post you current not working code snippet where you try to get the data from the option box and apply the changes to your cameraArray
shazam
11-05-2002, 04:11 PM
Here is the code i'm working with:
proc changeCameras()
{
string $cameraList[] = `ls -type "camera"`;
string $cameras;
string $film_gate = `optionMenu -q -value User`;
for ($cameras in $cameraList)
{
if (optionMenu -value User)
camera -e -horizontalFilmAperture .5;
camera -e -verticalFilmAperture .5;
}
}
artifish
11-08-2002, 11:22 AM
Originally posted by shazam
Here is the code i'm working with:
proc changeCameras()
{
string $cameraList[] = `ls -type "camera"`;
string $cameras;
string $film_gate = `optionMenu -q -value User`;
for ($cameras in $cameraList)
{
if (optionMenu -value User)
camera -e -horizontalFilmAperture .5;
camera -e -verticalFilmAperture .5;
}
}
there are some problems with your code:
- in your conditional statement, you create a new optionMenu, but you want to query the state of the optionMenu, so use the -q flag (like you did with $film_gate)
- as you already got the $film_gate, you should query its value in the conditional statement
- you forgot to specify the name of the camera in the camera-command ( camera -e -horizontalFilmAperture .5 $cameras; )
- currently, only the first camera-command is executed if the condition is true, but I guess you want both statements to be executed? add "{ [..] }"
dig a little deeper into mel and the docs and try to get your code working. i learnde a lot from reading scripts on highend that had some of the functionality i wanted to implement.
cheers, carsten
CGTalk Moderation
01-13-2006, 09:00 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-2012, Jelsoft Enterprises Ltd.