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