Sat, Nov 9, 11:49 AM 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: How to change an Image_Source path


JimX ( ) posted Thu, 15 June 2023 at 11:13 PM · edited Sat, 09 November 2024 at 11:41 AM

I am working on Materials. I have a particular node, and I have made inp the node's Image_Source input. When I execute:

   print(inp.Value() )

I get the full path to that image source. The value is just what I expected.

Now my question is how do I set that image source to a new, different path?


Y-Phil ( ) posted Fri, 16 June 2023 at 6:11 AM

Have you tried inp.SetValue(".....")? just be careful with the file path separator

𝒫𝒽𝓎𝓁


(っ◔◡◔)っ

👿 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, Sonoma 14.6.1, 16GB, 500GB SSD
👿 Nas 10TB
👿 Poser 13 and soon 14 ❤️


JimX ( ) posted Fri, 16 June 2023 at 10:29 AM

Thanks Y-Phil. Your caution about file path separators is important. I have been using os.path.join() to make sure that the separators are correct.

I had been using inp.SetString(".....") to set the value, as the documentation that I have does not mention any inp.SetValue. I had been looking for something like that. However, when I tried the SetValue() method, I got the error:

Traceback (most recent call last):

  File "/Users/jim/Library/Mobile Documents/com~apple~CloudDocs/Documents/Docs/Tech/Poser/Vic 4/Runtime/python/InTest.py", line 59, in <module>

    inp.SetValue(newFullPath)

AttributeError: 'poser.ShaderNodeInputType' object has no attribute 'SetValue'

So apparently, SetValue() doesn't exist on my version of Poser Python, which is in Poser 12 running on a Mac.

My problem with SetString() is that I get inconsistent results. Sometimes I even reboot and run the script again, and it comes out differently. There are two inconsistencies:

1. Sometimes the new string that is set into the Image_Source is the correct complete string. Sometimes it is just the file name, with all of the leading folders stripped off.

2. Sometimes the Image_Source data is updated. But more frequently the data is not actually updated at all-- so I do not effect any change.

------------

The context may be contributing to the confusion. I created a Python folder in my main runtime (not the one and the same folder as the app). I put this script in that folder. I then call the script from a specially-created shell .mt5 or .mc6 file. When I double-click on that materials file in the Poser library panel, it loads and the script is called.

What I am trying to do is to change the texture map without changing the transparency map. Or, alternatively, to change the transparency map without changing the texture map.

I have actually gotten this to execute correctly with an .mt5 file. So I have my hopes up that I may be getting close. But the script only if I have the Preview material selected (or, if I am in the Pose room, I respond to Poser's dialog box by saying 'Apply to Preview Material'). If I have the actual material to be changed selected, it does not change the Image_Source data. Frustrating, but at least I have detected a pattern there.

I have not yet gotten it to work at all from a similarly constructed shell .mc6 file.

----------

Any more ideas?






Y-Phil ( ) posted Fri, 16 June 2023 at 12:03 PM

From what I understand: SetString(...) is indeed the path to go.
I would say: if it works some times and fails at other times: is your path an absolute one?
I mean: on windows platforms, an absolute path starts by something like C:\... or a net path, such as \\my_server\my_folder\...
On Mac platforms, if I'm not wrong, an absolute path starts by "/".
If you edit an MT5 file or an MC6 file, using a simple text editor, you should be able to retrieve how Poser stores that absolute path.

𝒫𝒽𝓎𝓁


(っ◔◡◔)っ

👿 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, Sonoma 14.6.1, 16GB, 500GB SSD
👿 Nas 10TB
👿 Poser 13 and soon 14 ❤️


JimX ( ) posted Fri, 16 June 2023 at 12:57 PM

Actually, I've got a lot of print statements in the code, for debugging purposes. Here are the results from one run:


Old path: /Users/jim/Library/Mobile Documents/com~apple~CloudDocs/Documents/Docs/Tech/Poser/Vic 4/Runtime/textures/KozHair/PonyTailHair/KptTailTXblack.jpg

New path: /Users/jim/Library/Mobile Documents/com~apple~CloudDocs/Documents/Docs/Tech/Poser/Vic 4/runtime/textures/KozHair/PonyTailHair/KptTailTXblond.jpg

ext name: PoserSurface int name: PoserSurface type: poser

ext name: Color_Texture int name: Image_Map type: image_map

Pre Path: /Users/jim/Library/Mobile Documents/com~apple~CloudDocs/Documents/Docs/Tech/Poser/Vic 4/Runtime/textures/KozHair/PonyTailHair/KptTailTXblack.jpg

Aft path: /KptTailTXblond.jpg

ext name: Transparency_Map int name: Image_Map_3 type: image_map

Pre Path: /Users/jim/Library/Mobile Documents/com~apple~CloudDocs/Documents/Docs/Tech/Poser/Vic 4/Runtime/textures/KozHair/PonyTailHair/KptTailTR.jpg

Aft path: /Users/jim/Library/Mobile Documents/com~apple~CloudDocs/Documents/Docs/Tech/Poser/Vic 4/Runtime/textures/KozHair/PonyTailHair/KptTailTR.jpg


(You may have to go to Full Screen for those long lines to make much sense)

The first line ("Old path:....") is what I am looking to change. It is in a local string property called oldFullPath.

The second line (" New path:....") is the value that I am trying to insert into the Image_Source data. It is in a local string property called newFullPath.

The third and fourth (and seventh) lines are just to make sure I am going where I was intending, as I looped through the Shader Nodes.

The fifth line is just print(inp.Value) ). It shows what was in the Image_Source before I did anything. One important thing is that it matches oldFullPath.

Then I executed:

if inp.Value() == oldFullPath:
inp.SetString(newFullPath)

The sixth line is the result of:

print('Aft path:', inp.Value() )

after having executed the inp.SetString(newFullPath) statement. This is one of those cases where Poser (or Python) also stripped off all of the leading folders.

The eighth and ninth lines are the Before & After for the next node I found. Since the Before path was not the same as the path I was looking for (oldFullPath), the Image_Source data was not changed. This is exactly what I intended.


By the way, I checked in Poser's Material Room after having run the script. The Image_Source data in the Shader Node that referenced the texture map that I was trying to change was still what it had been before executing the script. So even thought the inp.Value() seemed to have changed while running the script, the change did not stick.


If you have any ideas for where to go next, they would be most appreciated.

  - JimX


JimX ( ) posted Fri, 16 June 2023 at 3:40 PM

Progress!

I got to wondering whether we were looking in the right place for the problem. The observation that the .mt5 hack only worked when the Preview material was selected gave me a clue. I had put the Python calls in the .mc6 files within each material section. I changed the .mt6 files so that all the Python calls for all the materials were in the Preview material section, and I eliminated all the other material sections.

It worked!

Problem solved. And (at least in the end), it wasn't a Python problem.


Y-Phil ( ) posted Tue, 20 June 2023 at 2:58 AM · edited Tue, 20 June 2023 at 2:58 AM

Great r0rMMbJe5RCCZ3vy9egf3llAmzVba6zgd3shDN1Z.gif

𝒫𝒽𝓎𝓁


(っ◔◡◔)っ

👿 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, Sonoma 14.6.1, 16GB, 500GB SSD
👿 Nas 10TB
👿 Poser 13 and soon 14 ❤️


JimX ( ) posted Fri, 23 June 2023 at 6:38 PM

With some wonderful help from Y-Phil, the solution is now tested and working on Mac and Windows, with Poser 11, 12 and 13, and so with both Python 2 and 3.

If anyone is interested in checking it out in earlier version of Poser, I have uploaded the scripts to Free Stuff, and called it "Load Specific Map." If you do, it would be nice if you would leave a comment about your results.


Y-Phil ( ) posted Sat, 24 June 2023 at 7:22 AM

JimX posted at 6:38 PM Fri, 23 June 2023 - #4468527

With some wonderful help from Y-Phil, the solution is now tested and working on Mac and Windows, with Poser 11, 12 and 13, and so with both Python 2 and 3.

If anyone is interested in checking it out in earlier version of Poser, I have uploaded the scripts to Free Stuff, and called it "Load Specific Map." If you do, it would be nice if you would leave a comment about your results.

Read your mail: I've found a solution for the space in file names U4zDuE6UTnA712elphgL3mqT0oaWWpdmdZDH7CWp.gif

𝒫𝒽𝓎𝓁


(っ◔◡◔)っ

👿 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, Sonoma 14.6.1, 16GB, 500GB SSD
👿 Nas 10TB
👿 Poser 13 and soon 14 ❤️


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.