The type enum property items for the operator is populated based on selection.
The type enum is an example of a dynamic enum that is populated dependant on selection.
As mentioned in my answer to this related question Add shortcut for Merge Last, and Merge First if you use
col.operator_enum("mesh.merge", "type") you get the available options.
"""Merge Panel in Mesh Tools"""
bl_label = "Merge"
bl_idname = "MESH_PT_merge2"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
#bl_category = "Tools"
def poll(self, context):
return context.mode == 'EDIT_MESH'
def draw(self, context):
layout = self.layout
col = layout.column()
if __name__ == "__main__":
I would like only the "At First, At Last, and Distance" buttons to be
Speculatively it looks like first and last options require vertex select mode and at least one vertex selected. An edit bmesh could be used to test, depending on your use case. this is probably overkill.
A try and except clause, except I generally recommend try to avoid these if possible.
In this case the error is thrown after the UI draws the button before the
type property is assigned, hence I've disabled.
for k in ['FIRST', 'LAST']:
row = col.row()
row.operator("mesh.merge", text=k.title()).type = k
row.enabled = False
Lastly, to get all the items possible in an operator enum
>>> rna = bpy.ops.mesh.merge.get_rna_type()
['FIRST', 'LAST', 'CENTER', 'CURSOR', 'COLLAPSE']