Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
there is no "stop" that I am aware of but there are ways to make it do what you are asking
for instance
import poser
scene = poser.Scene()
def test_for_light( ):
return True if scene.CurrentActor().IsLight() else False
if test_for_light():
put the body of your script here
else:
poser.DialogSimple.MessageBox("To run this script, please first select a light.")
or
import poser
scene = poser.Scene():
if scene.CurrentActor().IsLight():
do something
else:
send message
but you do not need to test if the current actor is a light if you are going to cycle through the lights anyway
you could do something like
import poser
scene = poser.Scene()
for light in scene.Lights():
light.SetLightOn( not light.LightOn() )
doing it this way, python would only affect lights, not other types of actors.
Locked Out
Thanks you so much, Structure, that's solved it. After a bit of rebuilding I now have a working script to turn off all lights except the currently selected one, do some useful things, then turn them all back on again.
I found, though, that at first I had 'invalid syntax' error on your 'Else:' — this was fixed by indenting all the way down the script. Below is a visual example of what I mean:
if test_for_light():
put the body of your script here
<- indent
<- indent
<- indent
<- indent
<- indent
<- indent
<- indent
<- indent
<- indent
else:
poser.DialogSimple.MessageBox("To run this script, please first select a light.")
In other words, the script has to have "a clear run" down the indents to get at the "else:" command. If not then it throws an 'invalid syntax' error. This should be useful to know for other beginners reading this in years to come.
Learn the Secrets of Poser 11 and Line-art Filters.
There is a Python function to abort a script: sys.exit()
But in Poser-Python this stops not only the script. It stops Poser :)
Nonetheless, there is a another, "pythonic" way to interrupt a running script (even if it's nicer done with program logic).
class StopScript(Exception):
pass
def abc(parm):
if parm > 10:
raise StopScript()
else:
print parm
try:
abc(20)
except StopScript:
print "Script aborted"
sys.exit()
Yes, I tried that. I'd never seen Poser exit so fast! Quicker than a Ctrl + Del and a forced stop, in Windows.
Thanks for the addition option, adp001.
Learn the Secrets of Poser 11 and Line-art Filters.
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
In PoserPython, is there any universal 'stop this script here, progress no further' command?
For instance:
actor = scene.CurrentActor()
# If no light is currently selected in the scene, then display this message and stop the script.
if not actor.IsLight():
poser.DialogSimple.MessageBox("To run this script, please first select a light.")
>>> STOP HERE! <<
else:
if actor.IsLight():
# OK, we have a light selected, so continue running the script.
lights = scene.Lights()
for light in lights:
What needs to go on the line >>> STOP HERE! << to cause the script to exit gracefully? I see "Return" used in other scripts, but that fails to prevent the script from continuing to run.
Learn the Secrets of Poser 11 and Line-art Filters.