Forum: Poser Python Scripting


Subject: Help needed with a script to witch off all lights

jenay opened this issue on Jul 12, 2008 · 5 posts


jenay posted Sat, 12 July 2008 at 6:51 AM

I am no longer sure, if it can be done with Poser5. I want to switch off
all lights of a given scene, without deleting nor changing the values and - optional -
to switch them on again.
here is a small script that does the job, but it's not exactly what I
envisioned. If I set all intensity values to 0, I cannot restore the original intensity
settings.
---8<---

Set Intensity of All Lights to 0

import poser

scene=poser.Scene()
lights=scene.Lights()
for light in lights:
 actor = scene.Actor(light.Name())
 print(actor)

for dials in actor.Parameters():

print (dials.Name())

 actor.Parameter("Intensity").SetValue(0)
scene.DrawAll()
---8<---

I found the SetOnOff method, but for the lights it is not what I need.
It only switches the "faked" light objects on and off, but not the lights
themselves.

some tips appreciated :)

 


nruddock posted Sat, 12 July 2008 at 7:29 AM

P5 lacks a method to just turn lights on and off without affecting the Intensity (SetLightOn(x) was introduced in P6).

I suspect that the only way to achieve what you want will be to write a pose file for the current light intensities, so that you can later restore them.
This is more complicated than what would be needed for P6 and above, so you may want to look at ockham's LightPanel script to see how that sort of thing is done.


markschum posted Sat, 12 July 2008 at 10:00 AM

I would write out the light values to a temp file , then you can read them back in later.

writing a file

myfile = "c:templightvalues.txt"
fo = file("myfile,"w")
for light in lights:
      write light.value + "n"

fo.close()
#reading a file
myfile = "c:templightvalues.txt"
fi = file(myfile,"r")
for line in fi :

set light to value from line

fi.close()


jenay posted Sat, 12 July 2008 at 12:58 PM

Hi All,
thank you for the advice :)

write out to a temp file would do the trick :)

 


markschum posted Sat, 12 July 2008 at 1:16 PM

There are other ways you could try, but the file method seems easy to implement .