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 โค๏ธ