Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
Beware of firewalls if you intend to use sockets, maybe ok if just for your own use but could prove a support headache if it will be for general release .
Not used sockets before with PoserPython API but link to simple demo code for Poser as the client, minor changes are required but runniing server component from your OS command line and loading the client code into Poser should work and provide a starting point. Simple socket code
I wrote some stuff about 12 years ago. (http://prpc.sourceforge.net/prpc.html) It's probably overkill for what you want to do.
I just picked up poser again after a 10 year hiatus. And it seems that the newest version of Poser has some limitations on running more than one python script at the same time. This can cause difficulties because the socket python code needs to be running all the time to communicate. Also, my PRPCd script uses Tkinter as a GUI. There seems to be a conflict between it and the Poser 11 library. I may rewrite the PRPCd to use wxPython. But I'm not sure.
Also, ADP has a UDP server to run in Poser. ADP writes some very very good clean code. http://www.poserprofis.de/python/scripts.xml He has a server and client. I haven't looked at them so I can't tell you much. It should be pretty straight forward. A lot less code than the PRPCd stuff.
I did try his work around for running more than one python script at the same time ( PPmaster.py ). Very neat idea. It didn't work for me in Poser 11, but I haven't really tried to debug it.
I took a look at the Marvelous Designer. That looks like an incredible product. I showed my 13 year old son who has an interest in fashion design and he was blown away by the tutorial videos.
Let me know how you make out. I'm just getting back into Poser and python programming. I should be up to speed in a couple months so let me know if you have questions or need help.
--tromnek
Update: I did try the simple socket code in Poser environment but it made Poser lock up. Maybe the Poser based examples give better results. The real life job kicked in but more time now. Figured out the other parts of the project like the .obj export from Poser. Now waiting for MD update with hopefully improved support for bridges. (MD had to postpone their GoZ bridge for technical problems so better wait for them to sort things out before I move in. They should be ready soon.)
Assume you're trying the server component in poser, client should work ok.
Running the server component of the simple socket code will cause a lock up because it doesn't return control back to Poser. If the server code is edited to jump out of the loop after the first successful connection you should see control pass back to Poser once the client has completed its connection and the script terminates. This is no good for your application, it was just intended as a basic example. Somekind of non blocking listener function is required for the server component that runs in the background. Possibly the wx timer can do this? I can't access tromnek's sample code so may this is already explained there.
@ironsoul: It was the server that I tried indeed. I considered I needed something that can listen before I try to make something that can talk. LOL! For my project I will need both anyway because it will be some 2-way communication.
@tromnek Thank you for confirming it still works. I had read somewhere that Tkinter and 64 bits systems and 64 bits Poser do not go well together. It is a ton of code, though. LOL!
I am now trying to get the application bits of the code to work: a one click method to save one of Erogenesis' mannequins as morphed as an object, and a one-click in MD to load that as a morph to the avatar. Having Poser prompt MD to load the avatar will be step 2. MD volley-ing the cloth geometry to Poser will be step 3.
The Tkinter works but it is non-re-entrant. So you can't run two tkinter programs at the same time.
I think Poser 11's library is tkinter based because it hangs until you exit PRPCd.
I have code in PRPCd to handle multiple tkinter instances, but you need to run PRPCd before any other tkinter program. I think Poser 11's library is tkinter and thus it runs first and things to work well.
I was thinking to rewrite my prpcd to use wxPython which works much better. But it's a lot of work to rewrite everything. Don't know when I'll get the time.
@tromnek: OK thank you for the explanation. I will concentrate for now on the application type parts. Apparently it is difficult to write a server that does not block the application. Just for my ignorance: those socket data: are they 'parked' somewhere if there is no active server? or does there need to be an active server to receive the message? .
FVerbaas posted at 2:20AM Thu, 07 December 2017 - #4319524
@tromnek: OK thank you for the explanation. I will concentrate for now on the application type parts. Apparently it is difficult to write a server that does not block the application. Just for my ignorance: those socket data: are they 'parked' somewhere if there is no active server? or does there need to be an active server to receive the message? .
Normally a connection open attempt will fail if the server is not up. In that case you could just use a timed loop to periodically attempt to open the connection until successful. How do you see the bridge working, ie what program initiates the transfer and how do you see the data being returned - maybe Poser hanging is not a problem unless the plan is to have both sides interactive throughout the process.
The server needs to check the socket for a connection periodically. You should check frequently enough so that an incoming connection to the server doesn't timeout.
It's not that hard to 'not block' the rest of the system. I used tkinter's .mainloop() to 'not block' and scheduled periodic checking of the socket with tkinter's .after(time2scheduleCall, function2call)
However, like I said, Tkinter messes up things in Poser. I over came that by hijacking Tkinter. But Like I said, you need to hijack before any other Tkinter starts up.
Using threads would probably be better I think there are some wxPython functions that could also be used.
ironsoul posted at 9:06AM Thu, 07 December 2017 - #4319559
Normally a connection open attempt will fail if the server is not up. In that case you could just use a timed loop to periodically attempt to open the connection until successful. How do you see the bridge working, ie what program initiates the transfer and how do you see the data being returned - maybe Poser hanging is not a problem unless the plan is to have both sides interactive throughout the process.
I have no exact plans yet. I think one side can be hanging during actual transfer process. It is short enough for that. However initiating transfer ideally should be possible from both sides. If they can blow a whistle or ring a bell to tell the other there is something to receive, that would be helping already. Then user can initiate a 'synchronize' action on the side where he did what he wanted to do and then on the other side get the update.
tromnek posted at 9:22AM Thu, 07 December 2017 - #4319560
However, like I said, Tkinter messes up things in Poser. I over came that by hijacking Tkinter. But Like I said, you need to hijack before any other Tkinter starts up.
And since you cannot be sure, better to avoid.
Using threads would probably be better I think there are some wxPython functions that could also be used.
Looks like a better route indeed. OK will start to dig out wxPython. Any recource recommended?
Have a look at AsynchronousSockets
I removed the lines a = wx.App(0) and a.MainLoop()
Added an import poser and scene = poser.Scene() at the top and changed handle_accept to print out the current actor name. Poser and the wxApp ran ok with the current actor part being displayed whenever the simpleclient script was run.
If the solution doesn't need to be socket based then another approach is shared memory and semaphores which that library appears to support. It will be important to use locking to prevent data corruption and always ensure the memory is released irrespective of the method of exit to prevent memory leaks.
You are right about the potential leak and seen my limited skills in Python there is a good chance I leave a few openings. The only way can get actual data into MD is by having MD read a file from disk, and vice-versa i can ask MD to write data to disk. The API simply does not let me do more than that. For Poser in theory I could bypass the HDD and write the geometry directly from shared memory into the scene, but that would be unduly complicated and load a file from disk is/should be more easy to achieve. So: the information shared needs not be more than the reference to the file. This is prety small so if I leave a gate open the memory leak will be small.
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.
Hello.
I would like to know if anyone has any experence with PoserPython in communicating with Pyhon in another application.
Let me explain the background: Marvelous Designer 7 comes with a Python API to support a/o import/export and read/write of data. (for the curious: information is here)
This would make it possible to build a 'bridge' between Posr and MD7 and use MD as an alternative cloth room, with all the features that MD offers, such as opening/closing buttons and zippers and manual intervention in the simulation. The example code that comes with MD shows how to do the data handling on that head of the bridge, and for the Poser side I presume there are some exmples how to export geometry etc. The problem lies with the communication and data transfer. The Royal way to do this I understand would be using sockets , My simpleman's method would be to start loops on both sides checking whether a specific file exists.
Does any of you have experience with this or with this sort of process interaction? Does PoserPython support sockets?