1

The duplicate post doesn't address the items in the dropdown. Only the bpy.types. The dropdown isn't part of that.

I'm have added a custom function to the face dropdown in the header region when in Edit mode. by appending to bpy.types.VIEW3D_MT_edit_mesh_faces

How do I change the order of my function in the dropdown list?

Here is a similar question but is addressing a different part of the UI.

what it looks like now: what it looks like now

what I want to see happen (doctored image): what I want to see happen (doctored image)

The script so far:

bl_info = {
    "name": "Custom Algo",
    "blender": (2, 80, 0),
    "category": "Face",
}

import bpy

class CustomAlgo(bpy.types.Operator):
    """Custom Algo"""
    bl_idname = "face.Custom_algo"
    bl_label = "Custom Algo"

    def execute(self, context):
        print("Pretend that you have done something sticky with that face")
        return {'FINISHED'}


def menu_func(self, context):
    self.layout.operator(CustomAlgo.bl_idname)

def register():
    bpy.utils.register_class(CustomAlgo)
    bpy.types.VIEW3D_MT_edit_mesh_faces.append(menu_func)

def unregister():
    bpy.utils.unregister_class(CustomAlgo)
    bpy.types.VIEW3D_MT_edit_mesh_faces.remove(menu_func)

if __name__ == "__main__":
    register()
Školstvo
  • 208
  • 1
  • 10
  • 2
    The answer is still the same as the question you linked: You can either prepend or append or do one of the workarounds listed. – Ray Mairlot Dec 02 '19 at 23:07
  • I think the existing answers are not clear. The accepted answer has dead links in it... A clear and well structured answer would be useful. I am voting to reopen it. – Martynas Žiemys Dec 03 '19 at 19:54
  • @Školstvo, you can re-register the whole menu in an add-on. You can right-click Blender's UI in some places and choose edit source to find out stuff like this. This menu is copied from source. – Martynas Žiemys Dec 03 '19 at 21:00
  • Right clicking anything in Blender 2.8 doesn't really do much of interest. – Školstvo Dec 03 '19 at 21:02
  • 1
    Sorry, I completely forgot about this – Martynas Žiemys Dec 03 '19 at 21:07
  • Sweet, didn't know about that. – Školstvo Dec 03 '19 at 21:10
  • 1
    I thought that re-registering a complete menu would mess up other add-ons trying to add stuff to it, but it seems to work when I test it even if I have one addon with new menu and another appending to it and in fact it's on a header that I have completely rewritten in another addon... I am not a professional programmer and lack in-depth knowledge in the area so there might be other problems with this, but I can see none at the moment. – Martynas Žiemys Dec 03 '19 at 21:15
  • @Ray Mairlot The workarounds don't really work for items in the dropdown list. When I hover over the existing items I see a reference to the operators that are activated by the elements, No reference to the elements themselves. – Školstvo Dec 04 '19 at 19:59
  • 1
    My tip is accept you can, easily, either append or prepend to layout. Whether inserting layout between operators in a menu's draw method or layout between menus (let's call it a menu not a drop down list) in a header's draw method (the dupe, now with a links fixed answer) the methods needed to achieve this, including code injection here https://blender.stackexchange.com/questions/57214/rearranging-elements-of-a-panel are IMO not worth the hassle. Instead spend your time on the "script so far" – batFINGER Dec 05 '19 at 04:22

0 Answers0