Notifications
Clear all

[Closed] How to turn on and turn off selected lights?

Hello everyone?
I want to ask a question

How to turn on and turn off all selected lights ?

14 Replies

to turn them off


for lights in selection do lights.enabled = false

to turn them on


for lights in selection do lights.enabled = true

Hi Yves,

Using the keyword lights might prove a bit problematic since lights is a collection in max. I tried it and it does seem to work if only lights are selected, but if I say:


for lights in selection do print lights.name
"Camera01"
"Camera01.Target"
"Spot02"
"Sphere01"
OK

you can see that lights is being used as a variable and might cause problems.

If I use a different property, like on then

for lights in selection do print lights.on=off
-- Error occurred in lights loop
-- Frame:
-- lights: $Target_Spot:Spot02 @ [90.355202,0.000001,-20.184021]
-- No ""="" function for (Global:print (prop on Local:lights))

If I say:


for l in lights do print l.name
"Spot01"
"Spot01.Target"
"Spot02"
"Spot02.Target"
OK

I get the names of all of the lights in the scene.

A better solution would be:

 
for l in selection do if superclassof l==light do l.on=not l.on

which will toggle the on status of any lights in sthe selection. Hope this is useful :>

J.

The where expression is very useful for these type of things:

for l in selection where superclassof l==light do l.on=not l.on
  • Martijn

nice one Martijn!

J.

hehe I just KNEW that lights was a common expression but it worked on selected lights

so I figured waht the hey

I guess that’s not proper education hehe.

But it DID work.

btw, in your l.on=not l.on

doesn’t that mean that if you have two lights, one on (x) the other off (y), that X gets turned of and Y gets turned on ?

2 Replies
(@magicm)
Joined: 11 months ago

Posts: 0

Yeah that’s what happens,

When the light is off, the expression evaluates to “not false” which is “true”
and the other way around; “not true” which is “false”

instead of using not l.on you can set it to either true or false to turn all those lights on or off explicitly.

  • Martijn
(@j-man)
Joined: 11 months ago

Posts: 0

Yes this is true, I just wanted to point out that there was another way to do it without having a script for turning things on and another for turning things off.
Something else you could say is:


for l in selection where superclassof l==light do l.on=selection[1].on

and this way all lights will match the first light that you select.

Thank Everyone!

but I do not understand .
I find a maxscript
mapped fn lightOnOffToggle obj =
(
try
(
obj.enabled = not (obj.enabled);
)
catch
(
)
)
lightOnOffToggle($selection);


but it can’t work if scenes have instan lights and mirror lights

Why do not I know

Who can help me let it work.

thank you

Hello,

If you turn off an instance, all other instances will also be turned off. The script you have will toggle on / off all of the lights in your selection, and all of their instances. This will do the same thing as what I posted before:


[left]for l in selection where superclassof l==light do l.on=not l.on[/left]

What is a mirror light?

J.

a mirror light is mirrored lights , Used the light of the mirror tool

J_man, Can you let it work

To the work that any light can be normal

mapped fn lightOnOffToggle obj =
(
try
(
obj.enabled = not (obj.enabled);
)
catch
(
)
)
lightOnOffToggle($selection);


Hi sy37,

If your light is an instance, then use the make unique button from the modify panel.

If you mirror a light (icon), then your light will become inverted although it will still function properly (AFAIK!)

If you have two lights in your selection and they are instances of eachother, if you execute this script then one will be turned off, then one will be turned on, and since they’re instances it will seem like nothing has happend.

Select one light and use this script, or make your lights unique!

J.

Page 1 / 2