1
$\begingroup$

I am traying to add node color and other material property to my pop up panel, but i was only able to add the Material Viewpor Properties so far.

Also, how do one go about finding out this? I was able to figure out the viewport properties, but this one my trial and errors didn't work, the source code seems to be quite more complex.

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

You need to get a reference to that material, then its node tree, then the principled bsdf node, and finally the color input field.

First make sure you have python tooltips enabled in your preferences :

enter image description here

And then you can get the path to most fields just by hovering over it or with right click > Copy data path.

See this question for more information.

In your case you could access this particular field from this particular material with :

import bpy


def draw(self, context):
    layout = self.layout

    # The name is case-sensitive :
    mat = bpy.data.materials["Material.005"]
    # Assuming you didn't rename the bsdf shader :
    principled = mat.node_tree.nodes["Principled BSDF"]  
    # Add the property in the layout. This will automatically create a color field. 
    # You can access inputs / outputs directly with their index or with their name as a string

    layout.prop(principled.inputs[0], "default_value", text="Color")  # Text argument is optional

Result : enter image description here

$\endgroup$

You must log in to answer this question.

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