Sat, Nov 23, 4:10 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: Turn off all DisplayOrigin points in a scene, at once?


HartyBart ( ) posted Wed, 14 July 2021 at 7:28 PM · edited Sat, 23 November 2024 at 4:06 PM

I am trying to make a universal script to "clear out all the unwanted items", ahead of the user making a Preview render in Poser 11. One of the many such unwanted item is the DisplayOrigin points (aka the 'green rods'), which you can see here.

turnoff.jpg

Clearing just one of these in a Poser scene is easy, but only for the current figure.

for actor in scene.Actors():
    actor.SetDisplayOrigin(0)

But what if the user wants a Preview render of the scene, yet has a half-dozen of these things messing up their scene? How to have a script turn them all off, regardless of if their originating body-parts or props are currently selected or not?



Learn the Secrets of Poser 11 and Line-art Filters.


HartyBart ( ) posted Thu, 15 July 2021 at 6:16 AM · edited Thu, 15 July 2021 at 6:21 AM

Well, this is weird. Testing again this morning I can't now get even the simplest possible script to remove any DisplayOrigin point in the test scene. Here is the full script.

import poser 
scene = poser.Scene() 

for actor in scene.Actors():
    actor.SetDisplayOrigin(0)

scene.DrawAll()

Does absolutely nothing, but it gives no errors. Yet the same script does work perfectly when targeting the Property "Visible", and does so across the scene.

It just seems utterly unable to hook into and affect the Property "DisplayOrigin". Changing the script to have the 'current selected item' explicitly targeted... makes no difference.



Learn the Secrets of Poser 11 and Line-art Filters.


adp001 ( ) posted Fri, 16 July 2021 at 11:31 AM

Seems like SetDisplayOrigin is broken (at least in P11). If you give a string as parameter, you will get an error message talking about "SetAnimatableOrigin".




primorge ( ) posted Fri, 16 July 2021 at 2:59 PM · edited Fri, 16 July 2021 at 3:03 PM

I'm puzzled. Display Origin only shows if you have that checked deliberately in parameters for that actor. You're saying that origins are showing by default in preview renders in Poser 11? Honestly as a matter of course I've done at least 1000 preview renders, easily more, since starting to use 11 and haven't seen that behavior once. In neither a saved scene or a new scene.


adp001 ( ) posted Fri, 16 July 2021 at 6:24 PM

There is a Python function meant to set the display origin on or off via script. But this function seams not to work.




primorge ( ) posted Sat, 17 July 2021 at 8:21 AM

OP said

"I am trying to make a universal script to "clear out all the unwanted items", ahead of the user making a Preview render in Poser 11. One of the many such unwanted item is the DisplayOrigin points (aka the 'green rods'), which you can see here."

OP is trying to clear out unwanted items, in this instance origin displays in preview render. Origin displays do not appear in preview render unless you methodically turn them on in every actor. OP says these are appearing by default in his scene, which indicates his installation of Poser 11 has some bug. It's not typical Poser behavior. In his above illustration, for example, I'm seeing primitive ball, Andy's wrist, and Andy's neck showing origin indicators. Which normally would only show if you were to activate that feature in each actor's parameters. The feature is off by default in all instances. OP indicates that it on by default in his Poser scene's previews...

blorg1.png2021-07-17.png


primorge ( ) posted Sat, 17 July 2021 at 8:31 AM

Unless I'm misunderstanding his phrasing, but that's how it reads to me. Turning on origins for things in a scene can be a tedious process, so it begs the question "why did user turn them all on in the first place?" as they are off by default and have a very specific use. So conjecture says that for some reason they are appearing as on by default, which is not typical poser behavior. At most, if it were deliberate, user might need to turn off say one origin indicator. OP's post indicates that all actors are showing the indicator, pointing to some default scene behavior in error by his language.


primorge ( ) posted Sat, 17 July 2021 at 8:35 AM

Guess we can only see intent by HartyBart's response. Just seemed curious to me. Apologies for any interruption.


adp001 ( ) posted Sat, 17 July 2021 at 8:39 AM

The first sentence of the OP reads:** I am trying to make a universal script to "clear out all the unwanted items",**

The point is: "trying to make a universal script".

For scripts Poser Poser Python has a function called SetDisplayOrigin(). The description of the function (the "doc" string):

Set if the origin of this actor should be visible in the preview.

https://www.posersoftware.com/documentation/12/index.htm#t=Poser_Python_Manual%2FMethods%2FActor_Methods.htm

But this function does not work at least in P11.




primorge ( ) posted Sat, 17 July 2021 at 8:46 AM

Well, if I'm misunderstanding his statement, not much of a loss to his script. End user typically would only need to turn off one origin display, easily enough done by toggling one check mark in properties. I think that if I'm misunderstanding it would arise from multiple actors showing it in his illustration. Which would be strange indeed, and aroused my curiosity.

Apologies again for any interruption.


adp001 ( ) posted Sat, 17 July 2021 at 8:47 AM · edited Sat, 17 July 2021 at 8:49 AM

primorge posted at 8:41AM Sat, 17 July 2021 - #4423383

Unless I'm misunderstanding his phrasing, but that's how it reads to me. Turning on origins for things in a scene can be a tedious process, so it begs the question "why did user turn them all on in the first place?" as they are off by default and have a very specific use. So conjecture says that for some reason they are appearing as on by default, which is not typical poser behavior. At most, if it were deliberate, user might need to turn off say one origin indicator. OP's post indicates that all actors are showing the indicator, pointing to some default scene behavior in error by his language.

Under certain circumstances it can make sense to switch on the Origins during the development of a scene. In order to create a quick, clean preview, a function for generally switching the origins can be useful.

But it is certainly also true that one can live without it :)




adp001 ( ) posted Sat, 17 July 2021 at 9:08 AM · edited Sat, 17 July 2021 at 9:11 AM

And already I have an application where I could use it to switch the origins on/off via script: I want to create a few dozen props with different geometries and parameters via script. To check if the geometries are correct and the props are placed correctly, it would be helpful if I could use "SetDisplayOrigin()" in the script.

Now I am forced to create pose files and load them for each prop where I want to switch the origins. Unnecessarily cumbersome, complex and slow...




HartyBart ( ) posted Sat, 17 July 2021 at 11:09 AM · edited Sat, 17 July 2021 at 11:15 AM

"SetAnimatableOrigin" - yes, thanks, that was one of the errors that was thrown in some configurations I tried. Good to know it's simply broken in Poser 11, and presumably 12 for now.

The assumption is that the user of the script wants to clear everything 'unwanted' before making a Preview render, and they might have such things lurking in the scene for some reason. They just want an automatic scripted way of making sure. I can think of four such circumstances. 1) The user has been tinkering and have forgotten they left some of the green rods 'on' for a few props, perhaps months ago. 2) They have loaded a scene, such as in this case from 2020 in the Smith Micro forums: "I was just playing with Ultimo Paradiso. It seems to have all items toggled to display origin on by default, and there are a lot of items in a scene." 3) The user has launched and used Sketch Designer and rendered to Sketch then gone back to Preview in Poser 11, and in certain circumstances in that case a purple 'origin ball' will appear every time. In this rare case the script in my first post does make it vanish, interestingly. 4) In the past I have loaded Star! props and they had the DisplayOrigin activated by default. Freebies, I think, probably quickly made and released. Or that the user just does not know how to hide various stuff from Preview, like light guide wires. Preview is important now, as it serves the real-time Comic Book Preview in Poser 11.

Anyway, here is the working script as it stands.

# Clear a Poser scene of unwanted guide gunk, before auto-rendering to PREVIEW. Then restore.
# Your Poser 11 scene is assumed to have it it a GROUND and one visible GROUP box.
# Version 1.3 working and with Grouping fix - thanks to RedPhantom for this part of the solution.

import poser

scene = poser.Scene()

# Turn off PREVIEW visibility of "Grouping 1" grouping box, assumed to be present in the scene.
# To do this we first select the Grouping box by its given internal name
# and set it as the current actor

scene.SelectActor(scene.Actor("Grouping 1"))
actor = scene.ActorByInternalName("Grouping 1")

# We set its Display Object mode to Texture Shaded in the Viewport.

poser.ProcessCommand(1409)

# We set its Transparency from 0 to 1 - which makes it invisible in the Viewport and in PREVIEW.
# To call this we have to use internal "SetTransparencyMax" command not the obvious "Transparency" mat label.
# Not sure this part is done "right", but it works for the Grouping box.

materials = actor.Materials()[0]
materials.SetTransparencyMax(1.0)

scene.DrawAll()

# Grouping box can still be manually selected via drop-down and used, but is now invisible 
# to the Viewport and to PREVIEW, while its parented items remain visible. We will have the 
# script restore the Grouping box later, after a PREVIEW render has been made.

# We now ensure all our scene lights do not display their guide-wires or wireframes in PREVIEW.

if (scene):
    lights = scene.Lights()
        for light in lights:
        if (light.LightOn()):
              light.SetOnOff(0)
        else: light.SetOnOff(0)

# We then try to ensure current selection's DisplayOrigin guides (aka 'axis wires' or 'green rods'
# or sometimes a 'purple ball') are off in PREVIEW.  These can be left on by accident or can be
# auto-activated on coming back from SKETCH Desiger to the Viewport for a PREVIEW render (bug?).

for actor in scene.Actors():
    actor.SetDisplayOrigin(0)

# It's possible the above bit may not work if you have a purple DisplayOrigin ball, due to a bug in Poser.
# Ideally you have no such DisplayOrigin points visible in your scene when you render.

# Now we hide all Deformers in the scene, such as magnets, force fields, waves. Visibility of
# these is restored later.

poser.ProcessCommand(1471)

# Now we optionally hide the EyeTarget box, if you have an eye-controller for both eyes.
# Available in the "Poser Python tools with source code" bundle at Renderosity.
# OPTIONAL - uncomment the following three lines of code, if this is useful for you.
#
#scene.SelectActor(scene.Actor("Figure EyeTarget"))
#actor = scene.ActorByInternalName("box_1")
#actor.SetVisible(0)

# Select the GROUND to make absolutely sure no bounding boxes, figure circles or similar are
# displaying on figures or props. GROUND must be present in the scene, but nearly always is.

scene.SelectActor(scene.Actor("GROUND"))

# Have OpenGL redraw the cleaned PREVIEW scene viewport, ready for rendering.

scene.DrawAll()

# Auto-render the scene to PREVIEW according to your currently-set dpi resolution and render size.

scene.SetCurrentRenderEngine(poser.kRenderEngineCodePREVIEW)
scene.Render()

# GROUND is still selected. So we re-select the Grouping box ready to reverse its invisibility.

scene.SelectActor(scene.Actor("Grouping 1"))
actor = scene.ActorByInternalName("Grouping 1")

# Now undo transparency on the Grouping box.

materials = actor.Materials()[0]
materials.SetTransparencyMax(0.0)

# Then have the Grouping box go back to its original wireframe Display Mode.

poser.ProcessCommand(1421)

# Now we unhide the EyeTarget box, if you have an eye-controller for both eyes.
# Available in the "Poser Python tools with source code" bundle at Renderosity.
# OPTIONAL - uncomment the following three lines of code, if it is useful for you.
#
#scene.SelectActor(scene.Actor("Figure EyeTarget"))
#actor = scene.ActorByInternalName("box_1")
#actor.SetVisible(1)

# Finally, unhide all Deformers in the scene, such as magnets, force fields, waves.

poser.ProcessCommand(1470)

# Have OpenGL redraw the restored scene in the viewport.

scene.DrawAll()

cleanprev.jpg



Learn the Secrets of Poser 11 and Line-art Filters.


primorge ( ) posted Sat, 17 July 2021 at 11:26 AM · edited Sat, 17 July 2021 at 11:34 AM

Thanks for the clarification. Makes sense, I've never encountered those particulars. Except for the light wires, and yes I just select the ground and it dispels them. It is annoying though.

I use the comic preview quite a bit, sketch renderer occasionally. Hopefully both of those features get some more attention in later releases.

Well done.


HartyBart ( ) posted Sat, 17 July 2021 at 2:55 PM

Thanks, primorge. There may still be more such items to add, that will also need to be cleared from a Preview scene once I discover what they could be.

The advantage of the lights-toggle part of the script (when used on its own) is that the user does not need to move the scene-selection away from their current figure, to make a render. This little script does look a bit redundant when included here, since the larger script is also selecting Ground. But I have occasionally seen lights stay visible in Preview when they've supposed to have been effectively 'turned off for Preview' by selecting Ground. Having both methods in the script provides a failsafe.



Learn the Secrets of Poser 11 and Line-art Filters.


structure ( ) posted Sun, 18 July 2021 at 1:17 AM · edited Sun, 18 July 2021 at 1:18 AM
Forum Coordinator

> # Turn off PREVIEW visibility of "Grouping 1" grouping box, assumed to be present in the scene.

to avoid script crashes You should never assume something is present in the scene.

You could use the following options to test for it before attempting to do anything with it.

option 1:

try:
    scene.SelectActor(scene.Actor("Grouping 1"))
    actor = scene.ActorByInternalName("Grouping 1")
   ... rest of script
except:
    pass

option 2:

if scene.Actor( "Grouping 1" ):
    scene.SelectActor(scene.Actor("Grouping 1"))
    actor = scene.ActorByInternalName("Grouping 1")
    ... rest of script

Locked Out


HartyBart ( ) posted Sun, 18 July 2021 at 5:04 AM

Thanks structure. This is what I have working now, with try / pass enabled for items that may or may not be in the scene.

14-with-passes.jpg



Learn the Secrets of Poser 11 and Line-art Filters.


adp001 ( ) posted Thu, 22 July 2021 at 8:30 AM · edited Thu, 22 July 2021 at 8:31 AM

Here is a wrapper class for actors. Use it like a normal actor.

import sys

if sys.version_info.major > 2:
    basestring = str

SCENE = poser.Scene()


class pActor(object):
    """
    Save access to Actor methods.
    For each method call SCENE.ActorByInternalName(self._iname).method([...]) is used.
    """
    __slots__ = "_iname",

    def __init__(self, ac=None):
        if ac is None:
            ac = SCENE.CurrentActor()
        elif isinstance(ac, basestring):
            try:
                ac = SCENE.Actor(ac)
            except poser.error:
                ac = SCENE.ActorByInternalName(ac)
        elif not isinstance(ac, poser.ActorType):
            raise AttributeError("Need an actor or an actors name to proceed.")
        self._iname = ac.InternalName()

    def __call__(self):
        return SCENE.ActorByInternalName(self._iname)

    def __getattr__(self, item):
        if not item.startswith("_"):
            return getattr(SCENE.ActorByInternalName(self._iname), item)


if __name__ == "__main__":
    actor = pActor()  # get current actor
    actor = pActor("Main Camera")  # get main camera, conventional name
    actor = pActor("MAIN_CAMERA")  # get main camera, internal name
    parm = actor.Parameter("Focal")  # get a Parameter




adp001 ( ) posted Thu, 22 July 2021 at 8:44 AM

Maybe it makes sense to wrap getattr with a try/except and return None in case of error.




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.