• Welcome to the Community Forums at HiveWire 3D! Please note that the user name you choose for our forum will be displayed to the public. Our store was closed as January 4, 2021. You can find HiveWire 3D and Lisa's Botanicals products, as well as many of our Contributing Artists, at Renderosity. This thread lists where many are now selling their products. Renderosity is generously putting products which were purchased at HiveWire 3D and are now sold at their store into customer accounts by gifting them. This is not an overnight process so please be patient, if you have already emailed them about this. If you have NOT emailed them, please see the 2nd post in this thread for instructions on what you need to do

How to check if a prop is (or isn't) in a scene

Gadget Girl

Extraordinary
Contributing Artist
I'm working on a script to quickly setup cloth simulations for an outfit I'm working on. And it works :) but one part of the script seems very awkward to me and I'm wondering if there is a better way.

Basically the outfit is in a few parts, pants and a top. Now I know that people may not always want to use them together. Specifically for my script what matters is if the user wants to use the top but not the pants. I need the script to behave slightly differently in that case. So I need to check and see if the pants are in the scene or not.

Here's the relevant part of the code:

Code:
import poser
scene = poser.Scene()

inscene = False
allActors = scene.Actors()
        for a in allActors:
            if a.Name() == "DawnPants":
                inscene = True
if inscene == True:
            sim.AddCollisionActor(scene.Actor("DawnPants"))

And yay! It works. But it seems like a lot of code just to check and see if an actor called DawnPants exists in the scene or not. Now it's possible this is the only way to do it, but I was wondering if there was a better way. I suppose it doesn't really matter because at the moment I have less than 50 lines of code, but it's the principle of the thing.

Any thoughts?
 
Last edited:

3dcheapskate

Engaged
That's the way I'd have done it
(...so I'd agree with you that there probably is a shorter, more elegant way to actually code it. But I can't think of one. :) )

Having said that, you could dispense with the inscene flag, and assuming you're only expecting one "DawnPants" in the scene:

import poser
scene = poser.Scene()

allActors = scene.Actors()
for a in allActors:
if a.Name() == "DawnPants":
sim.AddCollisionActor(scene.Actor("DawnPants"))
break
 

3dcheapskate

Engaged
Just reposting the code snippet from the post above but using 'Insert...' (from the row of buttons above the text entry box - the third little icon after the 'Smilies') > Code > General Code (there's no 'Python' option, just 'PHP' and 'HTML') to see if that preserves the tabs:

Code:
import poser
scene = poser.Scene()

allActors = scene.Actors()
for a in allActors:
    if a.Name() == "DawnPants":
        sim.AddCollisionActor(scene.Actor("DawnPants"))
        break

Looks like it does. :)
 

Gadget Girl

Extraordinary
Contributing Artist
Thanks guys. And thanks for reminding me where to find the code insert icon. I swore when I first posted it had preserved my indents, but clearly it didn't.

I guess it's just weird to me that there isn't a method to check if an actor is in the scene. Although I suppose if such a method existed, it would be basically just a version of what's been posted.

Having said that, you could dispense with the inscene flag, and assuming you're only expecting one "DawnPants" in the scene:

Oh, yes, I should have included the break. I did think about what if there are multiple items of the same name in the scene and I should check some thing to see what happens. Less because I expect there to be two instances of say DawnPants, but more to make sure if there are two figures in the scene, the clothing isn't trying to collide with say the wrong figures lForearm. I'll need to experiment and see what happens in this case because it's hardly uncommon to have two figures in a scene.
 
Top