evanhem opened this issue on Aug 31, 2020 ยท 13 posts
evanhem posted Mon, 31 August 2020 at 12:44 PM
Hi,
I am brand new to Poser Python. I have successfully written scripts using text editors to get data that I want. However, I would like to use PyCharm to edit my .py files. I am struggling to do things like importing the poser module and just getting access to the poser methods. I need to get over this hump and get PyCharm at least running so that I can learn more on my own. For now, I am just stuck setting it up. Is there a how-to on getting PyCharm to interact with poser?
I have read these threads:
https://www.renderosity.com/mod/forumpro/?thread_id=2941326
https://www.renderosity.com/mod/forumpro?thread_id=2942414
However, it is just a little too advanced for me to understand what I am doing. I have also bought the Python manual from Phil Cooke, which has aided me in getting started writing scripts in a text editor.
Thank you.
structure posted Mon, 31 August 2020 at 12:57 PM Forum Coordinator
adp001 wrote a script called poser_fake to allow for this check out his page
look for :Script Fake_poser3.py Class and Method headers to support editors while writing Python scripts.
Locked Out
adp001 posted Mon, 31 August 2020 at 1:22 PM
Here is a direct link to the ZIP. It contains the latest ready to go library beside of the script to create a include-lib for any Poser Python version (maybe even the next comming Python 3 version).
https://adp.spdns.org/FakePoserLib3.zip
evanhem posted Mon, 31 August 2020 at 7:36 PM
Thank you. It seems that I am failing to even "import poser." I have no issues with this when running PoserPython from Poser. Do I have to set some paths in PyCharm to get it to find poser?
Sets poser = None for me.
Then,
fails me:
Thanks for your patience.
adp001 posted Tue, 01 September 2020 at 5:12 AM
If you declare poser = None, what do you expect PyCharm should find in something that is nothing?
Some things you may have to know:
Poser-Python is directly implemented into Poser. Not reachable from the outside world. Also not from PyCharm. "POSER_FAKE.py" is a library you can "import" from a Python script like any other library with Python. Use it insteed of Poser Pythons own lib "poser" like so:
import POSERFAKE as poser
Or even better:
try:
import poser
except ImportError:
import POSERFAKE as poser
Make sure you saved the lib in a folder PyCharm (and your actual script) can reach while you develop.
evanhem posted Wed, 02 September 2020 at 1:07 PM
Thanks. I'm making incremental progress. The thing I am still confused about is how the actual program becomes involved. If I click on the forearm in the Poser window, how do I get PyCharm to return that Actor with CurrentActor()? Another example, I have Poser open now with 30 key frames:
Yet, when I run my .py file which imports your fake Poser library, the number of frames is returned as 1:
My main goal is to calculate joint positions of the Poser skeleton in time, and then animate the skeleton using matplotlib.
adp001 posted Wed, 02 September 2020 at 1:45 PM
Seems like you misunderstand some fundamental things.
There is no way to connect Poser directly to an external Python editor. The lib mentioned here only supports creating a script without Poser being involved (which is already a great help since the description of the functions is also shown).
The closest thing to your wishes is the Python shell built into Poser. It is not suitable for writing whole scripts, but you can access Poser's elements directly.
The shell can be found in the main menu under Scripts->Python Shell.
adp001 posted Wed, 02 September 2020 at 1:50 PM
AHHHH - I missunderstood you.
What you did wrong is to import POSER_FAKE while you actually needed poser!
use this:
try:
import poser
except ImportError:
import POSER_FAKE as poser
With this the external lib POSER_FAKE is only imported if the "real" poser is not available. And that is exactly what you want.
evanhem posted Wed, 02 September 2020 at 2:01 PM
I see. If there is no way to connect poser directly to an external editor, then what is the point of the try: import poser statement?
Otherwise, I do see the value of the fake poser library, as using PyCharm is a lot easier than writing Python scripts in a text editor. I guess I should save my .py files from PyCharm in the Python scripts directory for Poser, and call my script directly from Poser.
evanhem posted Wed, 02 September 2020 at 2:05 PM
Oh, is the try except statement so that when you run it from Poser, then it will successfully execute the try statement?
adp001 posted Wed, 02 September 2020 at 4:15 PM
You finally got it! :)
adp001 posted Wed, 02 September 2020 at 4:20 PM
And yes, you have to run the script with Poser-Python to get real values.
You can save the script in any directory you want, if you run it via Main Menu->Files->Run Python Script
evanhem posted Wed, 02 September 2020 at 6:28 PM
Thanks! Now I get to learn Python.