Sun, Nov 17, 1:40 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: Experience with communication between different instances of Python anyone?


FVerbaas ( ) posted Sat, 28 October 2017 at 2:28 PM · edited Sun, 17 November 2024 at 1:39 PM
Forum Coordinator

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?


ironsoul ( ) posted Sun, 29 October 2017 at 6:18 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



FVerbaas ( ) posted Sun, 29 October 2017 at 9:01 AM · edited Sun, 29 October 2017 at 9:04 AM
Forum Coordinator

This looks pretty clear indeed. Great! Thanx! Intention for now is to stay wihin same machine so there should be no firewall issues.


tromnek ( ) posted Wed, 01 November 2017 at 6:28 PM

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.


tromnek ( ) posted Wed, 01 November 2017 at 7:01 PM

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.


FVerbaas ( ) posted Tue, 07 November 2017 at 1:49 AM
Forum Coordinator

Great! Thanks for the pointers. Now all I need to find is the courage to go into this. LOL


tromnek ( ) posted Tue, 07 November 2017 at 8:44 AM

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


FVerbaas ( ) posted Sat, 02 December 2017 at 5:01 AM
Forum Coordinator

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.)


tromnek ( ) posted Sun, 03 December 2017 at 8:08 PM

What poser version are you running?

Yes I had that simple socket code lock me up also.

The PRPCd I wrote a long time ago still works. It could be modified for your use.


FVerbaas ( ) posted Mon, 04 December 2017 at 11:09 AM · edited Mon, 04 December 2017 at 11:12 AM
Forum Coordinator

I use Poser 11 Pro

Python version is 2.7.1

The other bridgehead, Marvelous Designer, uses version 2.7.11


ironsoul ( ) posted Mon, 04 December 2017 at 4:06 PM · edited Mon, 04 December 2017 at 4:07 PM

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.



FVerbaas ( ) posted Tue, 05 December 2017 at 2:09 PM
Forum Coordinator

@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.


tromnek ( ) posted Tue, 05 December 2017 at 10:22 PM

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.


FVerbaas ( ) posted Wed, 06 December 2017 at 12:19 PM
Forum Coordinator

@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? .


ironsoul ( ) posted Wed, 06 December 2017 at 8:53 PM · edited Wed, 06 December 2017 at 8:54 PM

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.



tromnek ( ) posted Wed, 06 December 2017 at 9:00 PM

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.


FVerbaas ( ) posted Thu, 07 December 2017 at 2:17 AM · edited Thu, 07 December 2017 at 2:22 AM
Forum Coordinator

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.


FVerbaas ( ) posted Thu, 07 December 2017 at 2:27 AM · edited Thu, 07 December 2017 at 2:29 AM
Forum Coordinator

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?


ironsoul ( ) posted Thu, 07 December 2017 at 3:46 PM · edited Thu, 07 December 2017 at 3:46 PM

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.



FVerbaas ( ) posted Fri, 08 December 2017 at 12:59 AM
Forum Coordinator

Great. I will check it out! Thanks!


tromnek ( ) posted Sat, 09 December 2017 at 1:15 PM

Yes that looks like the best way to go. Should be pretty straight forward.

I'm looking to use wxPython for everything in Poser. It seems to play nicely with Poser.


FVerbaas ( ) posted Sat, 09 December 2017 at 1:45 PM · edited Sat, 09 December 2017 at 1:58 PM
Forum Coordinator

Found out yesterday the Marvelous Designer bridgehead uses QtPy for user interface. (GRUNT!!!!)

Do you think it would be possible to connect to wxPython instead? I do not feel like learning two systems.
If I can get wxPython active by simply importing it, that would make it more easy for me.


ironsoul ( ) posted Sat, 09 December 2017 at 5:04 PM

Never say never but the two systems appear very different. If you don't want to develop two different GUIs one thought is to drive the commands from one side only using a second network connection as a command channel, would still be necessary to have a network server running at the other end.



FVerbaas ( ) posted Sun, 10 December 2017 at 2:48 AM · edited Sun, 10 December 2017 at 2:49 AM
Forum Coordinator

Heyhey. My needs are a little more modest than that.

The system id supposed to work within one computer, just the 2 apps each sending the other a signal if there is a file for the other to deal with. The address they know.


ironsoul ( ) posted Sun, 10 December 2017 at 5:23 AM

Doh, wrong phrase, meant to say it will still be necessary to have a script running on the other app to handle the requests but yes probably over complicated.



FVerbaas ( ) posted Sun, 17 December 2017 at 9:50 AM
Forum Coordinator

In the mean while someone pointed me at multiprocess functionality: http://docs.python.org/2/library/multiprocessing.html#managers Looks decent stuff but not sure if already supported on Mac.


ironsoul ( ) posted Mon, 18 December 2017 at 1:23 AM

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.



FVerbaas ( ) posted Mon, 18 December 2017 at 12:09 PM
Forum Coordinator

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.


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.