View Full Version : Help with script!
loked 08-05-2003, 09:22 PM Hey,
I'm trying to write a script that will let me search my scene for all the lights in the scene and then check to see which one of those lights have emitSpecular on. Once it has found which one do have it on, I want it to take their names and store it in an array. So that I can call this list of object up at a later stage.
Please any help is welcome. Thanks!
later:wavey:
loked
|
|
bigfatMELon
08-05-2003, 11:41 PM
there's this:
global proc string[] findLightsWithSpecular (){
string $pLights[] = `ls -type "pointLight"`;
string $sLights[] = `ls -type "spotLight"`;
string $aLights[] = `ls -type "areaLight"`;
string $result[];
for ($x in $pLights){
if (`getAttr ($x + ".emitSpecular")`)
$result[size($result)] = $x;
}
for ($x in $sLights){
if (`getAttr ($x + ".emitSpecular")`)
$result[size($result)] = $x;
}
for ($x in $aLights){
if (`getAttr ($x + ".emitSpecular")`)
$result[size($result)] = $x;
}
return $result;
}
-jl
loked
08-06-2003, 08:49 AM
Thanks, that is exactly what I needed, but just out of a matter of interest. Is there is any particular reason why you used a function, instead of just having the lights stay in the $result array and then whenever you want to call it up, you can just use the $result variable. Also, is there any reason as to why you seperated lights into spot, area and point instead of just using `ls -typ light`??
Once again, thanks very much for your help :thumbsup:
later:wavey:
loked
If you use `ls -type light`, you'll need to do 1 of 2 things. You either need to check and make sure you don't have an ambient light because it doesn't have a emitDiffuse attr and would cause the script to error OR just check for the attr before tring to get it!
Something like this:
string $allLights[]=`ls -type light`;
string $lights[];
for($i=0;$i<size($allLights);$i++)
{
if(`attributeQuery -ex -n $allLights[$i] emitDiffuse`){
if(`getAttr ($allLights[$i]+".emitDiffuse"){
$lights[size($lights)]=$allLights[$i];
}
}
}
--g
bigfatMELon
08-06-2003, 06:22 PM
The reason to make it a function is exactly the point you make: to have access to from any other code. All you need do from now on is ask...
string $stuff = `findLightsWithSpecular`;
...and move on from there. You can reuse it in other scripts as well. Even if reuse isn't your intention, programming in a modular way is a good for the debug cycle.
As for the three loops, I went that way because only spots, points and areas have an emitSpecular attr and well, I wote that thing really fast. The other suggestion for checking the existence of the attr is works too.
-jl
loked
08-06-2003, 08:47 PM
Alright, now I got you:thumbsup:
Thanks alot for all the help!
Take it easy!
later:wavey:
loked
CGTalk Moderation
01-15-2006, 07: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.