Correct way to define "DATA" for object.material_slots in a single bpy call I am quite happy with how the UI works now by calling a function I created for assigning the material to object or data:


class ApplyMaterialTo(bpy.types.Operator):
    bl_idname = "material.data"
    bl_label = "Material Data"
    bl_options = {'REGISTER'}

    def execute(self, context):
        bpy.context.object.material_slots[0].link = 'DATA'
        return{'FINISHED'}


    row = layout.row()
    row.operator("material.object", text="Set Object Material")
    row.operator("material.data", text="Set Data Material")


But I feel my approach is pretty convoluted. SO I tried to apply what I learned to day but this does not work:

row.operator("object.material_slots[0]").link=DATA


The resulting error message is:

Traceback (most recent call last):
  File "C:\Users\info\Desktop\Claas UI.blend\Claas_UI_2.py", line 174, in draw
NameError: name 'DATA' is not defined
The first error is that you are passing DATA a variable instead of string "DATA", hence you get DATA is not defined.

The second thing is object.material_slots[0] is not an operator, all operators resides in bpy.ops. ...  it is a variable,  when you write row.operator("object.material_slots[0]") it will try to call bpy.ops.object.material_slots[0] which doesn't exist.

you may want to make your own operator ( if there's none that can do this) and use it instead.

For this case it would be easier to let prop() handle this easily :

row.prop(object.material_slots[0], "link")


and it will display a combobox that you can chose from