Forum: Poser Python Scripting


Subject: Richard60' 7 Colors Color Ramp and my laziness...

Y-Phil opened this issue on Jul 01, 2023 ยท 15 posts


Y-Phil posted Sat, 01 July 2023 at 8:59 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... 
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 

๐’ซ๐’ฝ๐“Ž๐“


(ใฃโ—”โ—กโ—”)ใฃ

๐Ÿ‘ฟ 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

To be used in the Material Room.
Default:

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

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

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



๐’ซ๐’ฝ๐“Ž๐“


(ใฃโ—”โ—กโ—”)ใฃ

๐Ÿ‘ฟ 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

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.  :slight_smile:

_______________

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.


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.


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.  :slight_smile:


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