Thu, Jan 9, 5:22 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 Dec 02 3:16 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: Text window that pops up from an icon in a library.


davo ( ) posted Sun, 15 January 2023 at 1:56 PM · edited Thu, 09 January 2025 at 5:13 PM

I have no idea how python works, but I'm wondering if you can create a script or program that does something like this:

kvUw3inTfX0HGb6IArhfLaJ17xepORZ5jaNx7hhV.jpg

The image above shows that an icon in the library can open up a text window the click 'ok' to have it close.  It's like pulling up a readme file directly from the library. 

Can this be done in poser? I had to copy a dsa file (daz studio text file) and edit the wording, but it still works. I can copy the dsa file to any folder, edit the text, then save it. When I click on the icon from the library, the dsa file opens up and it can be closed.  I'd love to see something like this for Poser, a pop up window with info in it then close it.

Maybe a python script you can open up a dialog, add your read me notes and save it to a specific folder in your runtime libraries.  Then you can create a png file.

Any thoughts?


HartyBart ( ) posted Sun, 15 January 2023 at 7:00 PM · edited Sun, 15 January 2023 at 7:02 PM

The simple 'pop up a readme text message' bit is very easy in Python. If you download and install some Freestuff from Renderosity for Poser, then look in your Poser library, you'll probably find a working example of someone already doing that. For the causal editing of one of these, the Python .PY file is best opened and edited and save from the Notepad++ freeware on Windows. 

But it sounds like what you'd actually like is a dynamic 'Notepad in Poser' script doing the following:

1. Start the 'script maker' script, a new panel appears, into which the user types in some text and then presses "save".

2. The script saves the typed text as a new 'readme' .PY file, in the current Library folder. And alongside it adds a standard PNG icon saying "My Notes".

3. Each new user-created note persist in the runtime, and can be consulted in the future by going to the relevant folder. Possibly the user can also edit this earlier text on an ongoing basis, and save the new version.



Learn the Secrets of Poser 11 and Line-art Filters.


HartyBart ( ) posted Sun, 15 January 2023 at 7:40 PM · edited Sun, 15 January 2023 at 7:49 PM

Here's a simple example, with line-breaks and controls on the size of the panel that opens:


bJXzQwchzxnmqWR5O9PUanNYYJOmoDJHoZvJQoEA.jpg


import poser

message = "HEADER TEXT\n\nLine one text\nLine two text\n  Line three text\nLine four text\n Line five text."

dlg = poser.Dialog(file="./Runtime/ui/simpleDlgOk.xml"title="Title for panel"message=message, width=500height=250)
proceed = dlg.Show()



Learn the Secrets of Poser 11 and Line-art Filters.


davo ( ) posted Sun, 15 January 2023 at 8:12 PM

This is very helpful. I copied your information and pasted it, got it to work. I was trying to type a lot of text and the dialog box wound up being to narrow, the text disappeared off to the sides. Is there a way to have the text go onto the next line and have scroll bars if there is a lot of text? Some of my readme's get wordy.

PX1f54VNvpc0sz8JlvTNmtsGgiUpUhgyhnKNS2so.jpg


HartyBart ( ) posted Tue, 17 January 2023 at 4:51 AM

That's where the \n comes in. It forces a line-wrap ('new line').



Learn the Secrets of Poser 11 and Line-art Filters.


HartyBart ( ) posted Tue, 17 January 2023 at 5:15 AM

Ideally such messages are for prompting or reassuring the user, not for long readme files that need to be studied. You can also launch a PDF from a click on a Library icon for a script, which might be better in this case.



Learn the Secrets of Poser 11 and Line-art Filters.


Y-Phil ( ) posted Wed, 18 January 2023 at 9:16 AM · edited Wed, 18 January 2023 at 9:17 AM

If that interests you, you could also drop for example a CM2 file in a Pose folder, with a text file lying at the same place.

Example with a t.cm2, a t.py and a readme.txt files:

t.cm2:

{
version
{
number 9
}
runPythonScriptEx ":t.py" Readme.txt
}

then, the t.py Python file looks like this:

# -*- coding: utf-8 -*-
import codecs
import sys, os
if sys.version < '3':
    import __future__

path_to = sys.argv[0].split(os.path.sep)
path_to.pop()
path_to.append(sys.argv[1].strip())
f = codecs.open(os.path.sep.join(path_to), 'r', encoding='ISO-8859-1')
txt = f.read().replace('\r','')
print(txt)
f.close()

this Python script runs with Poser11 & Poser12. Tested on Windows.
The only pitfall: I have not found any way to change the colors: this is Poser's default run windows, and it's written in black on a white background. Nothing sexy.

𝒫𝒽𝓎𝓁


(っ◔◡◔)っ

👿 Win11 on i9-13900K@5GHz, 64GB, RoG Strix B760F Gamng, Asus Tuf Gaming RTX 4070 OC Edition, 1 TB SSD, 6+4+8TB HD
👿 Mac Mini M2, Sequoia 15.2, 16GB, 500GB SSD
👿 Nas 10TB
👿 Poser 13 and soon 14 ❤️


davo ( ) posted Wed, 18 January 2023 at 4:55 PM

@HartyBart: I was able to alter the width and height of the popup window so it was large enough to accommodate all the text. I did have to guess where to do the line break since all the text is centered instead of left justified.  Thanks for you help! This is a lot better method that I used do which what cram as much text onto a png file that showed up in the library.

@Y-Phil:  This is exactly what I was looking for and it works perfectly (after figuring out I needed to rename my source files).  Is there any way you know if to make the box wider perchance? It's not necessary since it has scrolling, but I'm just curious.

Thank you guys for your replies and help!


davo ( ) posted Wed, 18 January 2023 at 4:56 PM

Awww shizzle... I just realized I can dynamically stretch the box wider, duh...!


hborre ( ) posted Wed, 18 January 2023 at 7:18 PM

Can't read what HartyBart contributed because he blocked me for some reason.


nerd ( ) posted Wed, 18 January 2023 at 8:36 PM
Forum Moderator

Awesome. Definitely stashing this one in my bag of tricks.


adp001 ( ) posted Sat, 21 January 2023 at 2:39 AM

Maybe this is a bit more flexible:

"""
Create a Poser CR2 file with content similar to this:
{
version
{
number 11
}
runPythonScript "html/HtmlDialog.py"
}

Create a directory named "html" as a subdirectory where the CR2 file is located.
This subdirectory must contain the Python file called in the CR2 file.
The Python file contains the script below to display an HTML or text file.

In the demo script, the file must have the same name as the Python script,
but end in "html". HTML code must have a simple form only (no javascript
for example).

If the script is called "HtmlDialog.py", then the file to be displayed must
be called "HtmlDialog.html". Both can be changed as needed, of course.

All attributes of the used wx.html.HtmlWindow() class can be reached via
the dialog class (e.g. wx.html.HtmlWindow.LoadFile()
see https://docs.wxpython.org/wx.html.HtmlWindow.html.
"""

from __future__ import print_function

import sys, os, wx
from wx import html
try:
import poser
except ImportError:
import POSER_FAKE_12 as poser

html_file = os.path.join(os.path.abspath(sys.argv[0]).rsplit(".", 1)[0] + ".html")


class HtmlDialog(wx.Dialog):
def __init__(self, parent):
wx.InitAllImageHandlers()
super(HtmlDialog, self).__init__(parent, id=wx.ID_ANY, title="INFO",
style=wx.DEFAULT_DIALOG_STYLE |
wx.RESIZE_BORDER |
wx.STAY_ON_TOP)
self.browser = html.HtmlWindow(self, id=wx.ID_ANY, name="browser")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.browser, 1, wx.EXPAND)
self.SetSizerAndFit(sizer)
self.SetSize(500, 600)

def __getattr__(self, item):
return self.browser.__getattribute__(item)


if __name__ == "__main__":
dialog = HtmlDialog(None)
dialog.LoadFile(html_file)
dialog.SetSize(800, -1)
dialog.Show()





adp001 ( ) posted Sat, 21 January 2023 at 2:44 AM

The forum editor has once again destroyed the formatting. The intact source can be downloaded here:

https://adp.spdns.org/HtmlDialog.py




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.