PDA

View Full Version : Linking Light Intensity to a custom attrubute


Apophis3d
02-09-2008, 10:42 PM
I am looking for a way to link a lights intensity to a controler. Although in the linking editor I can not find an attribute for a lights intensity.

Basically this script will allow the user to selecte the lights in a scene. Then it will let the user rename the lights to whatever they want. All the lights in that scene will be able to have their intensity controled by the controler. That way you do not have to go though and selecte multipal lights.

I am not sure if I went about setting this up right. But when you run the script it should check to make sure if any lights are selected. If not it tells you none are selected. If you have a light selected it should ask you to rename the light. Then bind that lights intensity to the controler. I know I need some kind of loop but I really dont know where to go with my code i am at the point of confusion.

here is my code so far.

global proc lights(string $obj)
{
//Varables
string $sel[] = `ls -lt`;
int $num = `size($sel)`;

//creates circle
string $cir[] = `circle -normal 0 1 0 -name $obj`;

//Adds attribute
string $cir[] = `addAttr -ln "LightBrightness" -at double $obj`;
string $cir[] = `setAttr -e-keyable true ($obj+".LightBrightness")`;

//locks out unused attributes
$cir[] = `setAttr -lock true -keyable false ($obj+".sx")`;
$cir[] = `setAttr -lock true -keyable false ($obj+".sy")`;
$cir[] = `setAttr -lock true -keyable false ($obj+".sz")`;
$cir[] = `setAttr -lock true -keyable false ($obj+".rx")`;
$cir[] = `setAttr -lock true -keyable false ($obj+".ry")`;
$cir[] = `setAttr -lock true -keyable false ($obj+".rz")`;

//selects lights
if ($num == 0)
error "Nothing selected";






}

ashishdantu
02-11-2008, 02:11 AM
heeyyyya Apophis3d,,

have you tried this ??

connectAttr -f LightControl.LightBrightness pointLightShape1.intensity;

probably u have selected the light in the viewport and when u open the connnection editor - it wont show u the intensity attribute b'se you have its transform node selected ??

you need to get the shape node loaded to see the intensity attribute ! was it this ??

Apophis3d
02-12-2008, 12:26 AM
mine has to be something like this

string $cir[] = `connectAttr -f ($obj+".LightBrightness+ $obj+".intensity`");

however this is not working

hers what I have so far

global proc lights(string $obj)
{
//Varables
string $sel[] = `ls -lt`;
int $num = `size($sel)`;

//creates circle
string $cir[] = `circle -normal 0 1 0 -name $obj`;

//Adds attribute
string $cir[] = `addAttr -ln "LightBrightness" -at double $obj`;
string $cir[] = `setAttr -e-keyable true ($obj+".LightBrightness")`;

//locks out unused attributes
string $cir[] = `setAttr -lock true -keyable false ($obj+".sx")`;
string $cir[] = `setAttr -lock true -keyable false ($obj+".sy")`;
string $cir[] = `setAttr -lock true -keyable false ($obj+".sz")`;
string $cir[] = `setAttr -lock true -keyable false ($obj+".rx")`;
string $cir[] = `setAttr -lock true -keyable false ($obj+".ry")`;
string $cir[] = `setAttr -lock true -keyable false ($obj+".rz")`;

//Connects Controler Intensity
string $cir[] = `connectAttr -f ($obj+".LightBrightness+ $obj+".intensity`");

//selects lights
if ($num == 0)
error "Nothing selected";






}

Norb
02-12-2008, 08:01 PM
You'll want to have it look like this:
connectAttr -f ($obj+".LightBrightness") ($sel[0]+".intensity");

It's also a good idea to put in some error checking at the beginning of your script to check if something is selected, and if your control object already exists.

On a side note, you don't need to store all your 'add and setAttr' commands in variables
setAttr -lock true -keyable false ($obj+".sx");

Apophis3d
02-13-2008, 06:03 AM
Thanks for the feedback everyone

I am sure ill be posting more over this next week. I have to make an interface this week.

CGTalk Moderation
02-13-2008, 06:03 AM
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.