[Closed] Macroscript error turning lights on and off
So I wrote this up real quick. Just started learning so bear with me
If you watch the video i select a light and run my macroscript which will turn it off if its on and vice versa then the script deselects it. For some reason it won’t work with multiple lights! Thanks!
here is the video:
http://www.screencast.com/users/Nick_S/folders/Jing/media/674359b1-31ce-4dbc-af5f-7ecb12864ad3
here is the script:
macroScript Macro9
category: “Nick’s Tools”
toolTip: “Light_Switch”
buttontext: “Light_Switch”
(
for obj in $ do
(
if $.on==true then
(
$.on=false
)
else
(
$.on=true
)
deselect $
)
)
Well the $ variable is a bit weird in that it will hold the currently selected item if ONLY ONE item is selected and an array of items when many items are selected. So in your case you are trying to set the “on” property on an array, and of course an array has no “on” property and it crashes.
Here’s how I would do it:
IF selection.count > 0 DO --make sure that something is selected, else do nothing
(
FOR theLight in selection WHERE (superclassOf theLight == light) DO --loop trough all the lights in the selection
(
IF theLight.on == true THEN --turn on and of accordingly
(
theLight.on=false
)
ELSE
(
theLight.on=true
)
)
deselect selection
)
Also, bare in mind that most third party plugin lights use different names for the on/off property…
I’m sure someone will one up me on this but…!
An even shorter version:
for o in selection where (superClassOf o) == light do o.on = (not o.on)
deselect selection
Jason that script will work with Max lights. But will break on Brazil and probably other renderers.
maybe something a little tighter?
for s in selection where superclassof s==light do (try (s.on=not s.on);catch())
J.
Well, I was going for readability before, but how about:
FOR l in $lights WHERE l.isSelected DO TRY l.on = NOT l.on CATCH()
clearSelection()
Just got into the office. Will try these out.
Mucho Gracias
…great they all work! Thank you