1
$\begingroup$

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()
$\endgroup$
9
  • 2
    $\begingroup$ The answer is still the same as the question you linked: You can either prepend or append or do one of the workarounds listed. $\endgroup$ Dec 2 '19 at 23:07
  • $\begingroup$ 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. $\endgroup$ Dec 3 '19 at 19:54
  • 1
    $\begingroup$ Sorry, I completely forgot about this $\endgroup$ Dec 3 '19 at 21:07
  • 1
    $\begingroup$ 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. $\endgroup$ Dec 3 '19 at 21:15
  • 1
    $\begingroup$ 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 blender.stackexchange.com/questions/57214/… are IMO not worth the hassle. Instead spend your time on the "script so far" $\endgroup$
    – batFINGER
    Dec 5 '19 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.