check scene for lights

Hi all,

I am writing a script that will do this:

1. Check if there are lights in the scene.

2. If there are no lights, create 3 point lighting and then link it to a point helper object.

3. But if there are lights in the scene, don't create new lights, select the lights and pass it into an empty array.

The problems I am having are that I can't seem to get the script to check the scene for lights.

Cheers
/Saij

Here is my code:

(
sLights = #()

if sLights.count != 0

then append sLights (for l in lights where ClassOf l != light collect l) else

fn lightCreate = --Ligh Creator

(

local alignObj = Point pos:[0,0,0] size:25 box:true cross:false Name:"AlignObj"

local keyLight = TargetDirectionallight name:(uniqueName"KeyLight") rgb:(color 255 255 255) shadowColor:(color 0 0 0) multiplier:1 pos:[600,-540,540] isSelected:on target:(Targetobject transform:(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0]))

local fillLight = targetSpot name:(uniqueName "FillLight_" rgb:(color 255 255 255) multiplier:0.5 pos:[-890,-630,410] isSelected:on target:(Targetobject transform:(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0]))

local rimLight = targetSpot name:(uniqueName "RimLight_") rgb:(color 255 255 255) multiplier:0.3 pos:[-100,890,70] isSelected:on target:(Targetobject transform:(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0]))

lightArray = (for l in lights where ClassOf l != light collect l)

lightArray.parent = alignObj

)

append sLights (lightCreate())

)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Saij's picture

Thanks guys

Thanks guys,

I am save yet again, thanks so much.

Cheers
/saij

barigazy's picture

Yep, you are right. That is

Yep, you are right. That is better solution for sure.
I convert lights collection to array because Saij
mentioned in #3 question. But no need to select lights to create array.

barigazy

Anubis's picture

no prob ;)

my tips was written to Saij.

my recent MAXScripts RSS (archive here)

Anubis's picture

Yes, Lights is builtin dynamic collection

You can convert that collection to Array using As operator, but if that's the whole script, I not see a reason to do that. Also I see that you'll link your lights to a Point helper in both cases, so why not to create that Point and then if no lights (lights.count == 0) create only new lights with your function, and finally link them, i.e. something like this:

--create the point helper
pHolder = Point pos:[0,0,0] --...
--if no lights, create new
if lights.count == 0 do createLigths()
--link them
lights.parent = pHolder

my recent MAXScripts RSS (archive here)

barigazy's picture

one more example

you can also use point helper as target object

if (lightsArr = lights as array).count != 0 then lightsArr else
(
	local dm = Point(), lightsArr = #()
	for i = 1 to 3 do
	( 
		in dm (lgt = mr_Sky_Portal light_Width:30 light_length:30 pos:[random -100 100,random -100 100,random -100 100])
		append lightsArr lgt
	)
	lightsArr.target  = dm ; lightsArr
)

barigazy

barigazy's picture

try this one


if (lightsArr = lights as array).count != 0 then lightsArr else
(
	local dm = Dummy(), lightsArr = #()
	for i = 1 to 3 do
	( 
		in dm (lgt = Omnilight pos:[random -100 100,random -100 100,random -100 100])
		append lightsArr lgt
	)
	lightsArr
)

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.