Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 08 5:10 pm)
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.
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)
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()
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)
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.
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.
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 ?