I'm looking at the ui_menu.py template script in Blender, and line 19 shows this line:

                              text="Select All by Type...",

enter image description here

I thought I could find the id name "object.select_by_type" by hovering over Select -> Select All by Type... in the 3D viewport, but when I did, I couldn't see any grayish popup saying something like "Python: object.select_by_type()". How can find the id name of submenus like this one?


After a lot of experimenting, I've seen that a submenu can be made from one of two functions in a Menu subclass: 1. self.layout.operator_menu_enum() or 2. self.layout.menu().

1. self.layout.operator_menu_enum()

enter image description here enter image description here

If it's from operator_menu_enum(), you can hover your mouse over each option and the description will have the same function. For example, in Select -> Select All by Type..., each option you hover over has the description Python: bpy.ops.object.select_by_type(type='[some option]'). That's a good hint to say that the "Select All by Type..." menu was made from self.layout.operator_menu_enum().

(As a side note, I also see that the parameter name shown in the description is what you put in the property parameter when you're calling operator_menu_enum(). So since the parameter name in select_by_type() was "type", I'd call something in a custom script like self.layout.operator_menu_enum(operator = "object.select_by_type", property = "type", text="select_menu test"). And if I was making my own operator subclass for operator_menu_enum, apparently the variable name for the EnumProperty() you define is the string you put in the property parameter of operator_menu_enum(). I guessed that from this question.)

2. self.layout.menu()

enter image description here enter image description here

If the menu is made from self.layout.menu(), you can hover over each option and you'll see different function names in the description. An example is View -> Align View. To find the id name string that you can use in self.layout.menu(), you can do a search in bpy.types. For example, here's the code and output I got from the Python Console when I was searching up bpy.types:

>>> for i in dir(bpy.types):
...     if "align" in i: print(i)

I checked for "align" in the if statement because I thought it was the most logical thing, seeing that the submenu name was "Align View". And also by best guess, I saw that "VIEW3D_MT_view_align" was the id name for this submenu (I double checked in a custom script with something like self.layout.menu(menu = "VIEW3D_MT_view_align", text = "align test")). Anyways, that's the best I can come up with. I couldn't find anything in google this time.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.