• 0 Votes - 0 Average
• 1
• 2
• 3
• 4
• 5
Post: #1
 Karina Primus inter pares Posts: 487 Joined: 07/2017 Reputation: 3
A fellow artist created a set of props for painters (the ones which paint walls etc.!)

He wanted a way to change the colour of the paint used, in all props in the scene, with a single click.

This is my solution (still WIP, esp. the Python script!)
Suggestions welcome.

EDIT: DELETED PREVIOUS BECAUSE UPDATED!

EDIT 02-09-18

NOTE:

This is just for evaluation, it's only the Python script updated!
Copy it over the previous one you got from me.

@perpetualrevison:
If you feel comfortable enough then please create an account here and let's continue the project here:

- To me it's far easier than having to hunt for posts and PMs across other forums.
- Also this forum makes it much easier to attach files, and even Python scripts, as you can see here:

• Disconnect the "Simple_Colour" node from "Custom_output_1".
• Plug the "Simple_Colour" node into the "Ambient_Color" Instead, set "Ambient_Color" to Black(0,0,0) and "Ambient_Value" to 0.000.
• Run the new script.

This should finally work.

K
Cheers!

Karina

Be nice to each other
05.09.2018, 07:03
Post: #2
 Perpetualrevision Active member Posts: 40 Joined: 08/2017 Reputation: 0
Thank you!! I will test it soon :-)
Post: #3
 Perpetualrevision Active member Posts: 40 Joined: 08/2017 Reputation: 0
I finally had a chance to test the script, and it does work (yay!), but with a few "hiccups" along the way.

For one, I wasn't able to get it to launch using the .pz2 file you put in the Gadget folder along with the .py and .png files. I had put your Gadget folder in my Poses library, but when I clicked on it, nothing happened.

So then I tried launching the script using the "Run Python Script" command from Poser's File menu, and that method worked. I got the dialog box where I could choose a new color and pick which items to apply the new color to. When I clicked on Open Colour, I got the macOS native color picker (which is great!), and I chose a new color.

But when I clicked Make, I got an "Oups" error message. I dismissed it and another one popped up, which I also dismissed. And then I noticed that the colors had indeed changed to my new color -- so it worked in spite of the error message!

I'm attaching an image with the screenshots I took to show you each step of the process. I hope that helps you further refine the script!

http://perpetualrevision.net/content/wp-...-Sept5.png
PS: I fixed the problem of the script not launching from the .pz2 file by taking these steps:

(1) Moved the script to a folder under PoserScripts and changed its name to remove all spaces and periods (except for the file extension)
(2) Changed the library file to an .mt5, renamed it to Launch-SetColourScript.mt5, and put it in the Materials library
(3) Changed the contents of the library file to:
Code:
{ version     {     number 6     } runPythonScript ":Runtime:Python:poserScripts:karina:SetColour.py" }

That works just fine and is more convenient, since I can include the script in the folder with all the other "Messy Painter" materials!
08.09.2018, 00:17
Post: #4
 Perpetualrevision Active member Posts: 40 Joined: 08/2017 Reputation: 0
After more testing, I found that the script does NOT produce any error pop-ups if I elect to have the new color apply only to the selected prop (rather than to "all props"). If I elect "All Props," then I get a bunch of error pop-ups, but after I dismiss them all, the new color gets applied to all props w/ the appropriate materials. I could not find a correlation between the number of error pop-ups and anything specific in the scene, like number of props or number of materials w/o a Simple_Color node, and I don't know Python well enough to debug the script.

I used the script to set up 14 color material presets for each of my "Messy Painter" props, so for my own use it was a big time saver! I will also include the script with the freebie set, with instructions on using it, but will direct users to you for further updates of the script, if that's OK.

I also made a few minor changes to the script so that the UI would be more readable on my MacBook, specifically for the action buttons. I'm attaching a zip of the setup as I have it now in my "Messy Painter" Materials library, so you can see the minor changes. The zip also includes the "How to Use the Script" PDF I made for the Documentation folder.

Post: #5
 Karina Primus inter pares Posts: 487 Joined: 07/2017 Reputation: 3
Hello again, and sorry for the late reply.

I was rather busy with RL affairs (a.k.a. work) this week. The few hours I had left I tried to work on the script, however without a specific error report I can't find out what actually causes the error messages.

This is not your fault, because I suppressed the typical python error messages like:

Code:
Traceback (most recent call last):   File "P:\POSER LIBRARY\Runtime\libraries\Props\### ___ALEKS PROPS______ ###\The Stars On 45\02 Randomize Stack.py", line 59, in MakeItSo     self.shuffleCovers(FIGURA)   File "P:\POSER LIBRARY\Runtime\libraries\Props\### ___ALEKS PROPS______ ###\The Stars On 45\02 Randomize Stack.py", line 93, in shuffleCovers     self.setValues(tree, a, texOffsets) NameError: global name 'tree' is not defined
I'll post a version of the script here ASAP (probably tomorrow) without the error suppression.
When you run this script, please copy ALL those error messages into a text document and post is here.

Sorry for the hassle, but none of my friends is using a MAC, so you'll have to serve as my "Guinea Pig" for the testing...

I already noticed the messed up formatting of the text in your previous "Sept5.png" but thought it might have to do with the text size "for impaired vision" which also never works well for me in Windows..

Yes, I'd like to:
Please wait at least until Monday before you release the freebie with my error-riddled script, because that could save both of us a lot of trouble with replies like "Doesn't work!!1!" .
Remember very few people actually read manuals:
They leech, try it and if it doesn't work immediately they delete it.
Hardly what we want to gain a good reputation...

If i only had a little more time.

Cheers

Karina

Be nice to each other
09.09.2018, 01:47
Post: #6
 Perpetualrevision Active member Posts: 40 Joined: 08/2017 Reputation: 0
(08.09.2018 20:18)Karina Wrote:  Yes, I'd like to:
Please wait at least until Monday before you release the freebie with my error-riddled script, because that could save both of us a lot of trouble with replies like "Doesn't work!!1!"

Here's another option that would give you more time: I can remove the script from the "Messy Painter" freebie packaging and instead let users know that your Batch Colour Gadget will be available on your ShareCG gallery when it's ready (assuming you plan to post it there?). It would probably be better for users to get the gadget from you directly, regardless, rather than via my freebie package, so that they can get updates as needed.

Quote:Remember very few people actually read manuals

Speaking of which, is there a way to make Python open a PDF file when a user clicks on a library MT5 file? I think more people would probably read Readme files and "how to's" if they could be launched from Poser's library!
09.09.2018, 11:28
Post: #7
 ironsoul Ambitious Posts: 1 Joined: 09/2018 Reputation: 0
(09.09.2018 01:47)Perpetualrevision Wrote:
(08.09.2018 20:18)Karina Wrote:  Yes, I'd like to:
Please wait at least until Monday before you release the freebie with my error-riddled script, because that could save both of us a lot of trouble with replies like "Doesn't work!!1!"

Speaking of which, is there a way to make Python open a PDF file when a user clicks on a library MT5 file? I think more people would probably read Readme files and "how to's" if they could be launched from Poser's library!

There is a discussion here: https://stackoverflow.com/questions/4345...-in-python

To make life easier suggest installing the pdf in the same directory as the python script as then you don't then need to worry were it is installed.
Unfortunately startfile function only works with Windows but it shows the method of finding the file.

scriptdir=os.path.abspath(os.path.dirname(sys.argv[0]))
os.startfile(scriptdir+"/mydoc.pdf")
Post: #8
 Karina Primus inter pares Posts: 487 Joined: 07/2017 Reputation: 3
First of all the promised script without the error message suppression:

@perpetualrevision:

I think it would be a good idea to not include it for now, but instead link people to my script.
Initially I didn't plan to make this a separate upload at ShareCG because it's rather specific and only of interest for developers to include in their sets (like yours, and one of mine soon to come).
However we can make it a two-prongued approach:
-
• I publish the script as a standalone as soon as it works without errors and then add a link back to your product à la "As used in this product: "hxxp. etc".
Now I'm curious for the error messages.

@ironsoul:

I once had a bookmark for stackoverflow, which I lost somehow, so nice to have them back.

I use something similar in my most frequently used runtime folders already:
Copy these three files into any runtime folder of your choice, and if you click the icon in the library it will open the folder in Explorer. Very handy!
Quote:     (left-click & "save image as...")

--> So I see it also can work on a MAC.

Quote:Much later update by Edward:
os.system works, but it only works with filenames
that don't have any spaces in folders and files
in the filename (e.g. A:\abc\def\a.txt).
might possibly be a non-issue as long as the .pdf document is in the same folder as the python script?

The only thing we would need to make sure is that our actual FILE.NAME doesn't contain any spaces and other symbold that MAC can't understand.
So make it "SetColour.py" in stead of "Set Colour.py".

Probably that would need more testing from @perpetualrevision's MAC..
.

@ Both of you:

Besides that , this is a really great way to facilitate access to the manual in a product, and I'm sure this will be accepted very well by the users of our products! (few are prepared to browse through folder after folder to get to the manual)
This will be a standard feature in all my future products.

Cheers!

Karina

P.S.:
My code (Windows)
Code:
import poser, os tmpPath = os.path.dirname(poser.ScriptLocation()) + "\The_Manual.pdf" if os.name == "nt": os.startfile(tmpPath) else:     import subprocess     subprocess.call(["open", tmpPath])

Be nice to each other
12.09.2018, 20:38
Post: #9
 Perpetualrevision Active member Posts: 40 Joined: 08/2017 Reputation: 0
(10.09.2018 17:21)Karina Wrote:  First of all the promised script without the error message suppression:

Good news: the "error message enabled" script did not generate any error messages! It worked as intended on individual items, on "all props" and on "all figures," so that's great! Granted, I no longer had the exact same scene I tested it on originally, so maybe there was an item in that scene that was causing the problem (and not the script at all). The scene I just tested it on has a few props and one figure that do NOT have the Simple_Color setup the script looks for, while the remaining items did, so that wasn't the source of the problem.

At any rate, it seems to work now! But I noticed that the commented bit at the top of the script still refers to Custom_Output1 rather than to the Ambient input, just FYI.

As for the "Open Folder" (and adapted to "open PDF") scripts, those don't work on a Mac, for whatever reason. In the Mac version of Poser, you can right-click (i.e., control-click) on a library item to get a "Show in Finder" option, as you can see in the attached screenshot, so Mac users don't need a script option for that functionality.

When I tried the modified script to open a PDF in the same folder as the script, nothing happened -- no error messages and no actions. Not sure why, but I might spend more time reading the StackOverflow thread IronSoul posted to see if I can figure it out. I've hesitated to apply what I've found about Python in general to Poser Python scripts b/c I don't know what Poser Python can and can't use. But it sounds like the "open file" functions should work.

THANK YOU both SO MUCH for your help!!

16.09.2018, 11:55
Post: #10
 an0malaus Ambitious Posts: 2 Joined: 09/2018 Reputation: 0
(10.09.2018 17:21)Karina Wrote:  First of all the promised script without the error message suppression:

@perpetualrevision:

I think it would be a good idea to not include it for now, but instead link people to my script.
Initially I didn't plan to make this a separate upload at ShareCG because it's rather specific and only of interest for developers to include in their sets (like yours, and one of mine soon to come).
However we can make it a two-prongued approach:
-
• I publish the script as a standalone as soon as it works without errors and then add a link back to your product à la "As used in this product: "hxxp. etc".
Now I'm curious for the error messages.

@ironsoul:

I once had a bookmark for stackoverflow, which I lost somehow, so nice to have them back.

I use something similar in my most frequently used runtime folders already:
Copy these three files into any runtime folder of your choice, and if you click the icon in the library it will open the folder in Explorer. Very handy!
Quote:(left-click & "save image as...")

--> So I see it also can work on a MAC.

Quote:Much later update by Edward:
os.system works, but it only works with filenames
that don't have any spaces in folders and files
in the filename (e.g. A:\abc\def\a.txt).
might possibly be a non-issue as long as the .pdf document is in the same folder as the python script?

The only thing we would need to make sure is that our actual FILE.NAME doesn't contain any spaces and other symbold that MAC can't understand.
So make it "SetColour.py" in stead of "Set Colour.py".

Probably that would need more testing from @perpetualrevision's MAC..
.

@ Both of you:

Besides that , this is a really great way to facilitate access to the manual in a product, and I'm sure this will be accepted very well by the users of our products! (few are prepared to browse through folder after folder to get to the manual)
This will be a standard feature in all my future products.

Cheers!

Karina

P.S.:
My code (Windows)
Code:
import poser, os tmpPath = os.path.dirname(poser.ScriptLocation()) + "\The_Manual.pdf" if os.name == "nt": os.startfile(tmpPath) else:     import subprocess     subprocess.call(["open", tmpPath])
I've had some experience with trying to emulate runPythonScript calls within a Poser file parser. My results for macOS indicate:

#scriptError = subprocess.call( [ script ] ) # Permission error
#module = __import__( script ) # Import by filename not supported

so I ended up using:

module = imp.load_source( scriptName, script )

which seems to execute python scripts correctly, without the permission or not supported errors of the two previous methods I tried.

Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.
 « Next Oldest | Next Newest »

Forum Jump: