For the Modifier by Type addon i need a better way to recreate a enum property menu.
Some Hints how to do that? 4x enum in 1x enum?
For the Modifier by Type addon i need a better way to recreate a enum property menu.
If you want to replicate the layout, modifiers are listed in the same order in rna.
import bpy
# Categories start on these modifiers
mods = ('DATA_TRANSFER', 'ARRAY', 'ARMATURE', 'CLOTH')
# Rna enum items are listed in same order as menu.
op = bpy.ops.object.modifier_add
enum_rna = op.get_rna_type().properties['type'].enum_items
mdict = {"Modify": [], "Generate": [], "Deform": [], "Simulate": []}
for item, cat in zip(mods, mdict):
for mod in enum_rna[enum_rna.find(item):]:
mod_id = mod.identifier
# Delimit at next item in mods
if mod_id != item and mod_id in mods[mods.index(item):]:
break
mdict[cat].append((mod_id, mod.name, mod.icon))
# There's an invalid entry called Surface at the end of "Simulate"
# category. It's a duplicate of Simple Deform so we remove it.
if mdict["Simulate"] and mdict["Simulate"][-1][0] == "SURFACE":
del mdict["Simulate"][-1]
class MODIFIER_MT_add_modifier(bpy.types.Menu):
bl_label = ""
def draw(self, context):
layout = self.layout
split = layout.split()
for cat, mods in mdict.items():
col = split.column()
col.label(text=cat)
for id_, name, icon in mods:
col.operator("object.modifier_add", text=name, icon=icon).type = id_
if __name__ == "__main__":
bpy.utils.register_class(MODIFIER_MT_add_modifier)
bpy.ops.wm.call_menu(name="MODIFIER_MT_add_modifier")
Wow that is great!
I’m not so deep with blender RNA and I don’t know where I could have found it!
Thank you to figure that out!