Thu, Dec 12, 4:33 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 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: Richard60' 7 Colors Color Ramp and my laziness...


Y-Phil ( ) posted Sat, 01 July 2023 at 8:59 AM · edited Thu, 12 December 2024 at 4:31 AM

I do like Richard60's 7 Colors Color Ramp but my laziness strikes in when it comes to set the in-between colors correctly and in a progressive manner... qJIibGGHuuO4EZhbPgnHmw6XiJ115eH4xEKJM2LY.gif
That why I've written this little thingie.


def find_sni_by_name(node, name):
    for sni in node.Inputs():
        if sni.Name() == name: return sni
   
    return None

def setup_ramp_colors():
    scene=poser.Scene()
    mat=scene.CurrentMaterial()
    tree=mat.ShaderTree()
    seven_color_ramp = None
    for node in tree.Nodes():
        if any(sno.Name() == 'Below Range Flag' for sno in node.Outputs()):
            seven_color_ramp = node
            break
    if not seven_color_ramp:
        return False
   
    sni1 = find_sni_by_name(seven_color_ramp, 'Color P1')
    sni8 = find_sni_by_name(seven_color_ramp, 'Gradiant End Color ')
    steps = [
        (sni8.Value()[i] - sni1.Value()[i]) / 6
        for i in (0, 1, 2)
    ]
    r, g, b = sni1.Value()
    for col in range(2, 8):
        sni = find_sni_by_name(seven_color_ramp, f"Color P{col}")
        r += steps[0]
        g += steps[1]
        b += steps[2]
        sni.SetColor(r, g, b)
   
    tree.UpdatePreview()

setup_ramp_colors()


If it helps someone: cool 
To use it:
- stay in Poser's Material Room
- setup Color P1 and 
Gradiant End Color
- run the script

Looks like Visual Studio Code's Copy function and Rendo's messages editor seem to collaborate correctly zMVZEghO5Np2ryA3cPr9Zm5L4PhZ2tM5jjAB0lyO.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 ❤️


Richard60 ( ) posted Sat, 08 July 2023 at 2:49 PM

Neat script.  However there a problem not with the script, but with Poser.  Currently you can appear to change the values on the inputs of a Compound Node but those values are not transmitted into the working of the Node itself.  In order to fully change the input values you need to make a small change to each input manually in order for Poser to know that an input has a new value.  The bad part is that you cannot change it to the same value.  So in this case click each color chip and select a color just below the top left column and it puts in a color very close to what was shown.  This is also a problem in Poser 12.

There is a ticket in and it is on a list of fixes.  Right now they are working on getting 13.1 ready for the end of the month.  

Poser 5, 6, 7, 8, Poser Pro 9 (2012), 10 (2014), 11, 12, 13


Y-Phil ( ) posted Sun, 09 July 2023 at 3:48 PM

Oh, you are right and I was aware of this, I simply forgot, sorry about that.
So here is a corrected version:


def find_sni_by_name(node, name):
    for sni in node.Inputs():
        if sni.Name() == name: return sni
   
    return None

def update_internal_node_color(sni, r, g, b):
    main_node = sni.ItsNode()
    compound = main_node.CompoundData()
    internal_node_name, internal_node_input = sni.InternalName().split(':')
    for node in compound.ContainedNodes():
        if node.InternalName() != internal_node_name: continue
        internal_sni = node.InputByInternalName(internal_node_input)
        internal_sni.SetColor(r, g, b)

def setup_ramp_colors():
    scene=poser.Scene()
    mat=scene.CurrentMaterial()
    tree=mat.ShaderTree()
    seven_color_ramp = None
    for node in tree.Nodes():
        if any(sno.Name() == 'Below Range Flag' for sno in node.Outputs()):
            seven_color_ramp = node
            break
    if not seven_color_ramp:
        return False
   
    sni1 = find_sni_by_name(seven_color_ramp, 'Color P1')
    sni8 = find_sni_by_name(seven_color_ramp, 'Gradiant End Color ')
    steps = [
        (sni8.Value()[i] - sni1.Value()[i]) / 6
        for i in (0, 1, 2)
    ]
   
    r, g, b = sni1.Value()
    for col in range(2, 8):
        sni = find_sni_by_name(seven_color_ramp, f"Color P{col}")
        r += steps[0]
        g += steps[1]
        b += steps[2]
        sni.SetColor(r, g, b)
        update_internal_node_color(sni, r, g, b)
   
    tree.UpdatePreview()

setup_ramp_colors()



𝒫𝒽𝓎𝓁


(っ◔◡◔)っ

👿 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 ❤️


ThunderStone ( ) posted Mon, 31 July 2023 at 12:36 PM


Just wanted to know how to use. Trying to make a rainbow from scratch.


===========================================================

OS: Windows 11 64-bit
Poser: Poser 11.3 ...... Units: inches or meters depends on mood
Bryce: Bryce Pro 7.1.074
Image Editing: Corel Paintshop Pro
Renderer: Superfly, Firefly

9/11/2001: Never forget...

Smiles are contagious... Pass it on!

Today is the tomorrow you worried about yesterday

 


Y-Phil ( ) posted Mon, 31 July 2023 at 1:20 PM · edited Mon, 31 July 2023 at 1:20 PM

To be used in the Material Room.
Default:

mLHpAFqpHSGChIaTrB1kMvDrG9ynuQwjcpoBRpED.png

The node remains selected. I select the color for P1, then the last one, example with greens:

ef3A4SoJJ6qny0jISHJA9Fg1kzNrRmnlKr5ya8J4.png

Other colors (P2 to P7) untouched.
Launch the script and  here is the result:

kn5gtj4l4GSDcYbYGg1amFYBTSH022b9TpiSXJnn.png

In the last version, the color chips inside the compound nodes are correctly set:

RukIN5rmDyiUYwRtN0ppbAzt88xXRS1MxT1aIGBP.png


𝒫𝒽𝓎𝓁


(っ◔◡◔)っ

👿 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 ❤️


ThunderStone ( ) posted Mon, 31 July 2023 at 2:48 PM

thanks... not really a rainbow but a gradient. Not bad, tho.


===========================================================

OS: Windows 11 64-bit
Poser: Poser 11.3 ...... Units: inches or meters depends on mood
Bryce: Bryce Pro 7.1.074
Image Editing: Corel Paintshop Pro
Renderer: Superfly, Firefly

9/11/2001: Never forget...

Smiles are contagious... Pass it on!

Today is the tomorrow you worried about yesterday

 


Miss B ( ) posted Mon, 31 July 2023 at 3:34 PM · edited Mon, 31 July 2023 at 3:34 PM

OK, now you've got me interested ... where can I find this 7-color color ramp?  Am I wrong in assuming it's downloadable somewhere, or is it no longer available?

_______________

OK . . . Where's my chocolate?

Butterfly Dezignz


ThunderStone ( ) posted Mon, 31 July 2023 at 8:07 PM

B, it is in free stuff. Search for "RICHARD60"


===========================================================

OS: Windows 11 64-bit
Poser: Poser 11.3 ...... Units: inches or meters depends on mood
Bryce: Bryce Pro 7.1.074
Image Editing: Corel Paintshop Pro
Renderer: Superfly, Firefly

9/11/2001: Never forget...

Smiles are contagious... Pass it on!

Today is the tomorrow you worried about yesterday

 


Miss B ( ) posted Mon, 31 July 2023 at 8:23 PM

ThunderStone posted at 8:07 PM Mon, 31 July 2023 - #4471584

B, it is in free stuff. Search for "RICHARD60"

Hey stranger . . . long time, no see.

Thanks a lot, I just found it.  🙂

_______________

OK . . . Where's my chocolate?

Butterfly Dezignz


Miss B ( ) posted Mon, 31 July 2023 at 8:31 PM
Y-Phil posted at 3:48 PM Sun, 9 July 2023 - #4469653

Oh, you are right and I was aware of this, I simply forgot, sorry about that.
So here is a corrected version:

OK Y-Phil, so is what I just downloaded from the Freebies section the most up-to-date version you've posted about?

_______________

OK . . . Where's my chocolate?

Butterfly Dezignz


Richard60 ( ) posted Mon, 31 July 2023 at 11:48 PM

@ThunderStone If you want a rainbow I would use the Expandable Color Ramp.  One of the options is to blend between 2 colors of the color wheel.

lZr1aA8umhd372rk5Ns48NR8naqzN7ES9q8unmTg.png

In the example above it just has 2 colors and does a HSV Far blend style.  What that means is that starts at a Blue color and works it's way around the color wheel towards Green. But in order to get there it has to pass through Red.  In Poser Red is Zero, Green is 120 and Blue is 240 if you were to use the HSV node to make colors. Below is the expandable color ramp with 6 colors Red 0, Yellow 60, Green 120, Cyan 180, Blue 240 and Magenta 300.  you can see those colors on the 2 edges. The bands in between are those colors and how the different blend styles effect the color shift.  I like the second (third if you count the edge colors) band in.  This is a simple gradient with the ease applied.  What that means is that the colors that define the start stop have a greater effectiveness and show for a longer time instead of being a straight gradient.

vKy5BMNAkiJDNh7YY84naiTK6NmtrDHinIHVr7EW.png

you can find more information about the blends in the PDF I included with the Expandable color ramps. The nice thing is that you can choose how many colors to make your ramp instead of being stuck with the 7 I had in the orignal version.


Poser 5, 6, 7, 8, Poser Pro 9 (2012), 10 (2014), 11, 12, 13


Richard60 ( ) posted Tue, 01 August 2023 at 12:09 AM

@ Miss B The 7 Color Color Ramp in the freebie area is the version that Y-Phil wrote his script for.  The second post of his is the correct version of that script to account for a problem in Poser that won't allow Python to make changes to a compound nodes inputs and have those changes flow into the workings of the compound node.  You also may wish to check out the expandable color ramp as it is made to more closely mirror what Blenders color ramp does.  I also have a Map Range node that Blender has that is missing from Poser but you can get the same results with my freebie.

Poser 5, 6, 7, 8, Poser Pro 9 (2012), 10 (2014), 11, 12, 13


Richard60 ( ) posted Tue, 01 August 2023 at 8:14 AM

Below is the expandable color ramp with 6 colors Red 0, Yellow 60, Green 120, Cyan 180, Blue 240 and Magenta 300. I made an error in the numbers. Should be Below is the expandable color ramp with 6 colors Red 0, Yellow 40, Green 80, Cyan 120, Blue 160 and Magenta 200. The color wheel goes from 0 to 239 and at 240 resets back to 0 Red.

Poser 5, 6, 7, 8, Poser Pro 9 (2012), 10 (2014), 11, 12, 13


ThunderStone ( ) posted Tue, 01 August 2023 at 9:47 AM
Richard60 posted at 8:14 AM Tue, 1 August 2023 - #4471615

Below is the expandable color ramp with 6 colors Red 0, Yellow 60, Green 120, Cyan 180, Blue 240 and Magenta 300. I made an error in the numbers. Should be Below is the expandable color ramp with 6 colors Red 0, Yellow 40, Green 80, Cyan 120, Blue 160 and Magenta 200. The color wheel goes from 0 to 239 and at 240 resets back to 0 Red.

Oooo! I got to see that!  Thanks! 


===========================================================

OS: Windows 11 64-bit
Poser: Poser 11.3 ...... Units: inches or meters depends on mood
Bryce: Bryce Pro 7.1.074
Image Editing: Corel Paintshop Pro
Renderer: Superfly, Firefly

9/11/2001: Never forget...

Smiles are contagious... Pass it on!

Today is the tomorrow you worried about yesterday

 


ThunderStone ( ) posted Tue, 01 August 2023 at 9:53 AM
Miss B posted at 8:23 PM Mon, 31 July 2023 - #4471585

ThunderStone posted at 8:07 PM Mon, 31 July 2023 - #4471584

B, it is in free stuff. Search for "RICHARD60"

Hey stranger . . . long time, no see.

Thanks a lot, I just found it.  🙂


Aging and hospitalizations doesn't leave me much options other than reading silently.  Couldn't resist helping out a friend tho.


===========================================================

OS: Windows 11 64-bit
Poser: Poser 11.3 ...... Units: inches or meters depends on mood
Bryce: Bryce Pro 7.1.074
Image Editing: Corel Paintshop Pro
Renderer: Superfly, Firefly

9/11/2001: Never forget...

Smiles are contagious... Pass it on!

Today is the tomorrow you worried about yesterday

 


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.