User input to change materials properties

Hi all,

I have been struglin with this and I can’t find a way to do it. :frowning_face:

I have made a script that takes care of resetting the values of some of material properties in the whole scene, but now I would like to let the user to decide what is the new default value for all those properties. Since some materials could have their own texture map attached I can not delete all the materials a assing a new one with new values.

Specifically I would want to let the user change the values for the node input [4], [5] and [7]

Could anyone shed some light on this:

import bpy


class ResetAllMaterialsOperator(bpy.types.Operator):
  """Affects all Materials in the scene"""
  bl_idname = "material.reset_all_materials_operator"
  bl_label = "Reset all Materials"
  bl_options = {'REGISTER', 'UNDO'}

  def execute(self, context):
    for mat in bpy.data.materials:
        if mat.use_nodes:
            for n in mat.node_tree.nodes:
                if n.type == "BSDF_PRINCIPLED" and n.label == "":
                        n.inputs[4].default_value = 0.75
                        n.inputs[5].default_value = 0.1
                        n.inputs[7].default_value = 0.5
                        
                        
                        
                        for l in mat.node_tree.links:
                            if l.from_node.type == "TEX_IMAGE" and l.to_node.type == "BSDF_PRINCIPLED":
                                if l.to_socket.identifier == "Alpha":
                                    mat.node_tree.links.remove(l)
                        break
                    
                                    
    return {'FINISHED'}



class testPanel(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "TEST 2"
    bl_label = "Test label"

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

        box = layout.box()
        row = box.column()
        row.operator("material.reset_all_materials_operator")


def register():
    bpy.utils.register_class(testPanel)
    bpy.utils.register_class(ResetAllMaterialsOperator)
    


def unregister():
    bpy.utils.unregister_class(testPanel)
    bpy.utils.unregister_class(ResetAllMaterialsOperator)
    
    
    
    
if __name__ == "__main__":
    register()

Thanks in advance,
Juan

I got the solution overe here thanks to batFINGER