Notifications
Clear all

[Closed] noob trying to script

ok so i am just tring to make a simple script to turn lights on and off.
i can make a vray light go on and off but not a max default one.
i also know that max and vray lights have different settings for things and have taken that into account but still nothing.


for i in $* do
– if classof i == VRayLight then i.on = off
if classof i == VRayLight then i.on = on

that works

for i in $* do
if (Superclassof n == Light) then i.on = Disable
if classof i == Omni_Light then i.on = enable
if classof i == Light then i.on = enable
if (namePrefix == “nitelite”) then lt.enabled = Enable

none of these work and i dont know why… can anyone help me?

also the script lister is not erroring out

4 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

enable and disable are not valid boolean values, so none of the second part attempts would work. You need true|false or on|off passed to the .on property.

Then there are a couple of lights that do not have an .on property – for example Area lights and Brazil lights. These would need special case handling.

You don’t have to loop through all scene nodes – there is a built-in Lights object set containing all lights in the scene.

So for the general case, you could say

for o in Lights where hasProperty o "on" do o.on = false

or

for o in Lights do try(o.on = true)catch()

These should work for 95% of the cases. For the special cases, you might need a classof test as you did in your Vray test.

The following creates a single light of each class installed on your machine:

for o in light.classes do 
try( execute (o as string + " pos:(random [-100,-100,-100] [100,100,100])"))catch()

Then you can run the OFF code from above and see which ones remain enabled. Then select one of those and use

show $

to see what the properties are really called…

wow thanks bobo!!
i really appreciate the assistance… i have been tring to revers engineer other scripts but cant find any that deal with lights

that all seems to be working – one element that is needed.

i need this to only operate on an object whos name startes with “nitelite”.

works, all the lights in the scene <thank you>, minus mental ray ones <dont care>

for o in Lights where hasProperty o “on” do
– if (namePrefix == “nitelite”) then o.on = true
o.on = true

no work.

for o in Lights where hasProperty o “on” do
if (namePrefix == “nitelite”) then o.on = true
–o.on = true

im using the “namePrefix” because it is already part of the script so i thought it should work, but i am doing somthing wronge

Nameprefix is most probably a user variable created by the script you were looking at, it is not a built-in Max function or property.

for o in Lights where matchPattern o.name pattern:"nitelite*" do try(o.on = false)catch()
 
 for o in $nitelite* where hasProperty o "on" do o.on = false

you are a god!

thank you many many times sir, if i ever hear anyone looking for a scripter ill pm you…

though your probly happy at frantic

CHEERS!!!