Perhaps I’m misunderstanding but it sounds as though
the object already has materials applied and you just don’t know how many prior to loading a specific object.
You shouldn’t need additional properties for this. Granted the below is specifically looking for a principled bsdf shader and adjusting the default base color; but the concept of accessing the active objects material properties remains the same.
import bpy
class TESTADDON_PT_Main(bpy.types.Panel):
bl_idname = "TESTADDON_PT_Main"
bl_label = "Test Addon"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Test"
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
if context.object and context.object.material_slots:
obj = context.object
obj_mats = [m.material for m in obj.material_slots]
for mat in obj_mats:
if mat and mat.use_nodes:
bsdf = mat.node_tree.nodes.get("Principled BSDF")
row = col.row(align=True)
row.prop(bsdf.inputs['Base Color'],
"default_value",
text=mat.name)
def register():
bpy.utils.register_class(TESTADDON_PT_Main)
def unregister():
bpy.utils.unregister_class(TESTADDON_PT_Main)
if __name__ == "__main__":
register()