Sat, Nov 23, 3:24 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 this the best way to select a prop with an unknown name?


HartyBart ( ) posted Tue, 10 August 2021 at 11:11 PM · edited Sat, 23 November 2024 at 1:02 PM

One prop has been loaded into a Poser scene, but the scene has "No Actor" selected. This can happen when the user loads a prop alongside a figure, then deletes the figure.

Running this script will then usefully select the one prop present in such a scene (whatever the prop's name might be).

import poser
scene = poser.Scene()

actor = scene.Actors()
for prop in scene.Actors():
    if prop.IsProp():
        scene.SelectActor(prop)

Is this the best way to do the script?



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


structure ( ) posted Wed, 11 August 2021 at 12:50 AM · edited Wed, 11 August 2021 at 2:25 AM
Forum Coordinator

while the script you wrote would work ( mostly, there are a few things to take into account ):

Writing the script in this fashion you would only be able to have 1 prop in the scene. This script cycles through all the props in the scene and always finishes on the same prop.

like this...

"chandelier" is it a prop?
    yes
        select it
    no
        ignore it

"truck" is it a prop?
    yes
        select it
    no
        ignore it

"dynamite" is it a prop?
    yes
        select it
    no
        ignore it

resulting in the script always selecting dynamite last and thus that being your selected prop.

Perhaps a better way to implement it would be to pass the selection over to the user

like so:

class dialogs:
    def choose( self, title = "", prompt = "", OptionList = [] ):
        dialog = wx.SingleChoiceDialog( None, prompt, title, OptionList )
        if not OptionList == []:
            return dialog.GetStringSelection() if dialog.ShowModal() == wx.ID_OK else None

import poser
propnames = []
scene = poser.Scene()
for actor in scene.Actors():
    if actor.IsProp() and not actor.IsBodyPart():
        propnames.append( actor.Name() )

if len( propnames ) > 0:
    selectThis = dialogs().choose( "CHOOSE PROP", "select a prop", propnames )
    try:
        scene.SelectActor( scene.Actor( selectThis ))
    except:
        pass

If however, the prop has no name, then you would need to give it one

actor.SetName( "tempname" )

then use

scene.SelectActor( scene.Actor( "tempname" ) )

Also some actors cannot be selected without destabilising poser,(eg centerofmass) so you would also have to account for those.

using something like this ( a rework of a Snarlygribbly snippet )

class valid:
    def IsValid( self , actor , bodypart=False ): # a modified function of a Snarlygribbly routine
    if not actor == None:
        n       =   actor.Name().lower()

        if n.endswith("con") or n.endswith("con 1"):
            return False

        data    =   [
                    'atmosphere','background','bodymorphs','centerofmass',
                    'faceroom','focusdistancecontrol','ground','grouping',
                    'universe'
                    ]
        
        for d in data:
            if d in n:
                return False

        if actor.IsZone() or actor.IsBase() or actor.IsDeformer():
            return False
    
        if actor.IsLight() or actor.IsCamera():
            return False

        if actor.IsProp() or ( actor.IsBodyPart() and bodypart == True ):
            return True

    return False

then change this line

if actor.IsProp() and not actor.IsBodyPart():

to

if actor.IsProp() and valid().IsValid( actor ):

-----------------------------------------------------------------------------

also you might want to remember your variables

you assign

actor = scene.Actors()

but then never use actor to reference anything.

Locked Out


adp001 ( ) posted Wed, 11 August 2021 at 3:41 AM

This "Snarly" snippet: Forget it as fast as you can.




adp001 ( ) posted Wed, 11 August 2021 at 9:33 AM · edited Wed, 11 August 2021 at 9:39 AM

Yes, props can be many things. Not only objects that can be rendered.

Which brings us to what you can test: If you don't want the various control props, but only the ones you can render, then it's best to test for the presence of geometry. If there is no geometry, then we don't care what kind of control prop it is.

proplist = [ac for ac in poser.Scene().Actors() if actor.IsProp() and hasattr(actor, "Geometry") and actor.Geometry() is not None and actor.Geometry.NumVertices() > 0]
if len(proplist) == 0:
    print("No usable props in this scene.")
elif len(proplist) == 1:
    print("The one and only prop: ", proplist[0]
else:
    # make something to select one of the props.
    print("All the props:", proplist)




HartyBart ( ) posted Wed, 11 August 2021 at 5:03 PM

Thanks to structure for the 'user in control' variant. I'm trying for hands-off automation for a specific use-case (in which the user will load only one prop). But your clear example could certainly be useful in the future, and for others too. I did look for an example of a simple 'user selects one object from list' script, but failed to find one even in Phil C's bundle.

Thanks adp001 for the tip and code on the initial geometry testing. That looks very useful to know about, especially as I have a basic working 'one-click to clear away all items that could clutter or mar a Preview render' script. I may add your check into that when I go back to that script at some point.



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


structure ( ) posted Fri, 13 August 2021 at 3:20 AM · edited Fri, 13 August 2021 at 3:22 AM
Forum Coordinator
proplist = [ac for ac in poser.Scene().Actors() if actor.IsProp() and hasattr(actor, "Geometry") and actor.Geometry() is not None and actor.Geometry.NumVertices() > 0]
if len(proplist) == 0:
    print("No usable props in this scene.")
elif len(proplist) == 1:
    print("The one and only prop: ", proplist[0]
else:
    # make something to select one of the props.
    print("All the props:", proplist)

I Just tried this and this was the list of props returned from a new installation default scene :

FocusDistanceControl
GROUND
CenterOfMass
GoalCenterOfMass
rThumb0Con
rIndex0Con
rMid0Con
rPinky0Con
rRing0Con
lThumb0Con
lIndex0Con
lMid0Con
lRing0Con
lPinky0Con
UpperBrowCon
RightOuterBrowCon
LeftOuterBrowCon
MidBrowCon
RightInnerBrowCon
LeftInnerBrowCon
RightUpperEyeLidCon
LeftUpperEyeLidCon
RightLowerEyeLidCon
RightUpperCheekCon
LeftUpperCheekCon
RightLowerCheekCon
LeftLowerCheekCon
NoseCon
RightNostrilCon
LeftNostrilCon
UpperLipCon
RightUpperLipCon
RightLipCon
LeftUpperLipCon
LeftLipCon
RightEarCon
RightEarLobeCon
LeftEarLobeCon
LeftEarCon
LeftLowerEyeLidCon
RightBreastCon
LeftBreastCon
RightGluteCon
LeftGluteCon
LowerLipCon 1
RightLowerLipCon 1
LeftLowerLipCon 1
JawCon
MonsPubisCon
AmorHair
CenterOfMass
GoalCenterOfMass

which leads me to believe ( based on this script testing for valid geometries ) that FocusDistanceControl, CenterOfMass, and GoalCenterOfMass all have geometries; if that is the case, then this script fails to eliminate props that you would not want to have show up in your list.

Locked Out


HartyBart ( ) posted Fri, 13 August 2021 at 3:39 AM · edited Fri, 13 August 2021 at 3:40 AM

That's interesting, thanks. I just tested my initial script (see top of thread) with my "'No Actor' selected" use-case.

First use: the script switched from 'No Actor' to select the one prop in the scene, as expected.

Second use: the prop stays selected (or, is re-selected, after the slightest flicker).

Third use: I delete the prop. 'Main Camera' is then auto-selected by Poser. I run the script, and GROUND is selected.

So yes, it seems GROUND is indeed a prop.



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


structure ( ) posted Fri, 13 August 2021 at 4:15 AM · edited Fri, 13 August 2021 at 4:23 AM
Forum Coordinator

Yes ground is a prop as are all the cameras and lights - but special case props such as centerofmass need to be eliminated from the returned list.

further examination gives :

FocusDistanceControl, has Geometry : True, Number of Vertices : 3463
CenterOfMass, has Geometry : True, Number of Vertices : 324
GoalCenterOfMass, has Geometry : True, Number of Vertices : 324

Locked Out


structure ( ) posted Fri, 13 August 2021 at 4:26 AM · edited Mon, 20 September 2021 at 7:29 AM
Forum Coordinator

the following script will find the first valid actor and select that actor.

import poser

scene = poser.Scene()

class valid:

    def IsValid( self , actor , bodypart=False ): # a modified function of a Snarlygribbly routine

        if not actor is None:

            n       =   actor.Name().lower()

        if n.endswith("con") or n.endswith("con 1"):

            return False

        data    =   [

                    'atmosphere','background','bodymorphs','centerofmass',

                    'faceroom','focusdistancecontrol','ground','grouping',

                    'universe'

                    ]

        for d in data:

            if d in n:

                return False

        if actor.IsZone() or actor.IsBase() or actor.IsDeformer():

            return False

        if actor.IsLight() or actor.IsCamera():

            return False

        if actor.IsProp() or ( actor.IsBodyPart() and bodypart == True ):

            return True

    return False

for actor in scene.Actors():

    if valid().IsValid( actor ):

        # find first valid actor and select it 

        scene.SelectActor( scene.Actor( actor.Name() ) )

        break

Locked Out


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.