I was making a blender add-on 1 year ago, and it can apply shader nodes to the selected object. Now I run my script again, it cannot display the result I did of last year. So, I think it maybe because of different version but not sure.

My problem:

The image below is a dialog box for selecting color and roughness, but now it shows nothing. enter image description here

Here is a part of my script for making the panel, button and the dialog box:

class Shader_Glass(bpy.types.Operator):
    """Add a Glass Shader."""
    bl_label = "Glass"
    bl_idname = 'shader.glass'
    #Add dialog box (color)
    col = bpy.props.FloatVectorProperty(name= "Color", subtype= 'COLOR_GAMMA' , size=4, default= (0.665, 0.672, 0.692, 1))
    roughness = bpy.props.FloatProperty(name='Roughness', default= 0.120, min= 0, max= 1)

    def draw(self, context):
        layout= self.layout
        layout.separator(factor= 0.1)
        box = layout.box()
        box.prop(self, "col", slider= True)
        box = layout.box()
        box.prop(self, "roughness", slider= True)
        layout.separator(factor= 1)
    def execute(self, context):
            #Create a Shader Material and name it Glossy Silver
        material_glass = bpy.data.materials.new(name= "Glass")
            #Use Nodes for this Material
        material_glass.use_nodes = True
            #removed Principaled BSDF node
        material_glass.node_tree.nodes.remove(material_glass.node_tree.nodes.get('Principled BSDF'))
            #Get material output
        material_output = material_glass.node_tree.nodes.get('Material Output')
            #material location
        material_output.location = (600,0)
        material_output.select = False
            #Minimize the Node
        material_output.hide = True
            #Create the Glossy BSDF Node       
        BsdfGlass_node = material_glass.node_tree.nodes.new('ShaderNodeBsdfGlass')
            #Setting the Location 
        BsdfGlass_node.location = (0,-100)
            #Setting the color & roughness value
        BsdfGlass_node.inputs['Roughness'].default_value = self.roughness
        BsdfGlass_node.inputs['IOR'].default_value = 1.333
        BsdfGlass_node.inputs['Color'].default_value = self.col
            #Deselect the Node
        BsdfGlass_node.select = False
            #Minimize the Node
        BsdfGlass_node.hide = True
            #Reference to the Material ouput node
        outputmaterial = material_glass.node_tree.nodes.get('Material Output')
        outputmaterial.location = (200,0)
        outputmaterial.select = False

            #Creating links between the 
        material_glass.node_tree.links.new(BsdfGlass_node.outputs[0], material_output.inputs[0])
            #Adding Material to the currently selected object
        bpy.context.object.active_material = material_glass
        return {'FINISHED'}
    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self, width= 230)
  • 1
    $\begingroup$ See last item of release notes : wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API/… $\endgroup$
    – Gorgious
    Jan 6, 2022 at 12:18
  • $\begingroup$ @Gorgious Are you telling me to read Class Property Registration ? So I need to change the = of bpy.props to : $\endgroup$
    – userN08
    Jan 6, 2022 at 12:37
  • $\begingroup$ Yes, and do the same for roughness $\endgroup$
    – Gorgious
    Jan 6, 2022 at 12:45
  • $\begingroup$ Thank you very much, it works well. I will paste the code as answer. $\endgroup$
    – userN08
    Jan 6, 2022 at 12:46
  • $\begingroup$ Nice ! Please do. Cheers :) $\endgroup$
    – Gorgious
    Jan 6, 2022 at 12:46

1 Answer 1


According to Class Property Registration of the release notes: https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API/Addons

Classes that contain properties from bpy.props should be assigned using a single colon : in Blender 2.8x instead of equals =

Now, my code changes to this:

col: bpy.props.FloatVectorProperty(name= "Color", subtype= 'COLOR_GAMMA' , size=4, default= (0.665, 0.672, 0.692, 1))
roughness: bpy.props.FloatProperty(name='Roughness', default= 0.120, min= 0, max= 1)

And result is:

enter image description here


You must log in to answer this question.

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