Sat, Nov 23, 2:08 PM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Is there a universal "stop this script here" command?


HartyBart ( ) posted Sun, 19 July 2020 at 7:38 PM · edited Sat, 23 November 2024 at 1:46 PM

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.


structure ( ) posted Sun, 19 July 2020 at 8:26 PM · edited Sun, 19 July 2020 at 9:12 PM
Forum Coordinator

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


HartyBart ( ) posted Sun, 19 July 2020 at 9:41 PM

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.


structure ( ) posted Sun, 19 July 2020 at 10:22 PM
Forum Coordinator

Glad you got it working

Locked Out


adp001 ( ) posted Mon, 20 July 2020 at 2:54 AM

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"




HartyBart ( ) posted Mon, 20 July 2020 at 5:54 AM

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.


Privacy Notice

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.