Mon, Sep 9, 5:26 AM CDT

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 08 5:10 pm)

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: Adding function to poser.Scene()


semidieu ( ) posted Fri, 22 April 2011 at 4:19 AM · edited Mon, 26 August 2024 at 4:39 PM

Is there a way to add a function to poser.Scene() ?

For example, I would like to create a function/method that returns the currently selected object (prop or figure).

So, I create a function:

 

def CurrentSelection():

_____obj = poser.Scene().CurrentActor()

_____if obj.IsBodyPart():

__________obj = poser.Scene().CurrentFigure()

_____return obj

 

 

Now, I would like to use it like this:

poser.Scene().CurrentSelection()

 

Is this possible ?


nruddock ( ) posted Fri, 22 April 2011 at 4:59 AM

As the object returned by poser.Scene() is a wrapped native object, it doesn't allow you to add new members just by assignment, and there is no dict attribute to manipulate.

Even if the implementation allowed you to modify a scene object, you'd have to make the same modification each time you called poser.Scene() as the wrapper object returned is different for each call.

Basically any object with a dict attribute can be extended, but you have to be careful of wrappers as their lifetime may not be the same as the underlying native object.


semidieu ( ) posted Fri, 22 April 2011 at 5:08 AM · edited Fri, 22 April 2011 at 5:08 AM

Thanks for the reply... All the things I tried wasn't working... Now I know why :)

So I'll keep my usual way for scripting :)


bagginsbill ( ) posted Fri, 22 April 2011 at 6:18 AM

However, the poser module is a dict and you can replace Scene with your own function, which can make and return anything. From there you can wrap the native scene object and revise or delegate every scene method, as well as add new ones. Note: the scene object's lifetime is not tied to what we think of as the scene, i.e. doing File/New does not cause an existing scene to go away or become different. So you could build a wrapped object just once and keep returning it forever.


Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)


semidieu ( ) posted Fri, 22 April 2011 at 7:14 AM

Thanks BB. But when you do this, can you get all original function and add you own without having to re-write all the Scene original functions ?


nruddock ( ) posted Fri, 22 April 2011 at 8:48 AM

Quote - But when you do this, can you get all original function and add you own without having to re-write all the Scene original functions ?

You'd have to save the original method under a different name so that you can call it later. E.g.

poser.SceneOrig = poser.Scene

You can then call the original method using poser.SceneOrig()


bagginsbill ( ) posted Fri, 22 April 2011 at 10:41 AM

I think he was referring to all the scene methods - i.e. after he returns his own object, how does it inherit all the methods of the real scene object.

It's easy. Go read about getattr, and also the Python Proxy class.

In a nutshell, getattr is called when an object does not seem to implement a response to a message. It means that an attribute or a function has been invoked on your object, and your object doesn't seem to have any such thing. This is your opportunity to delegate the request to some other object.

In your case, your custom scene object would have something like:

def getattr(self, what): return getattr(self.originalNativeScene, what)

This would delegate to the original scene object (of course you must have already stored that.)


Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)


adp001 ( ) posted Fri, 22 April 2011 at 10:51 AM

I made something like this in 2008 already.

Download http://www.poserprofis.de/python/ADP_UDPserver.zip

In this Zip you'll find a script named PPmaster.py. This script defines some classes as Wrappers for Scene, Figure, Actors and the lib poser. It's more a studie to show how to do, so feel free to extend this concept. One of the important parts is a sort of "event-framework" for callbacks.




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.