1
$\begingroup$

I wanted to add a color field to my Blender addon panel, with which I can adjust the color input of a Principled Volume node. But i´m struggling, how I can insert such a color field there and synchronize it with the color field of the Principled Volume. Does anybody know how to do that? I would appreciate every help!

$\endgroup$
1

1 Answer 1

0
$\begingroup$

check this out:

import bpy

def hndl_draw(self, context):
    row = self.layout.row()

    row.prop(context.object.data, "myColor")
    
def get_color(self):
    return bpy.data.materials["Material.001"].node_tree.nodes["Principled Volume"].inputs[0].default_value
    
def set_color(self, value):
    bpy.data.materials["Material.001"].node_tree.nodes["Principled Volume"].inputs[0].default_value = value
    return 

def register():   
    bpy.types.Armature.myColor = bpy.props.FloatVectorProperty(
                                     get=get_color,
                                     set=set_color,
                                     name = "myColor",
                                     subtype = "COLOR",
                                     size = 4,
                                     min = 0.0,
                                     max = 1.0,
                                     default = (0.75,0.0,0.8,1.0)
                                     )
                                     
                                     
                                     
    bpy.types.DATA_PT_display.append(hndl_draw)

def unregister():
    bpy.types.DATA_PT_display.remove(hndl_draw)
    del bpy.types.Armature.myColor

if __name__ == "__main__":
    register()

Note1: i used the solution from here: Color as Custom Property?

Note2: i changed it a bit

Note3: you need a material called "Material.001" with a principled volume in it with exact the name i used, and an armature

result:

enter image description here

hope that helps.

$\endgroup$
1
  • 1
    $\begingroup$ Many thanks Chris, i came to a quite similar solution yesterday and it works! $\endgroup$ Commented Mar 31 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .