[PYTHON] Restore menu items that disappeared in Blender 2.8 or later

This article will be posted as an article to fill in the blank article on the 3rd of the Qiita version of Blender Advent Calendar 2020. https://qiita.com/advent-calendar/2020/blender

In 2020, partly because of the first long-term support version of Blender 2.8 It was a year when the transition from Blender 2.7 series to 2.8 or later progressed.

Although the function itself has not changed since Blender 2.8, There are some menus whose display position has been moved.

For example, some of the side menus and face menus in edit mode. image.png In 2.79, there was a duplicate of the *** side loop *** and *** side ring *** related to the side menu *** related to the side menu. After 2.80, each selection menu is only in the normal menu and disappears from the side menu and face menu. It's nice that it was refreshing, but it became complicated for those who remember *** mainly with shortcuts ***

Therefore, I would like to use the add-on function to restore the items in the menu.

Sample add-on

First from the sample code


bl_info = {
    "name": "add menu item",
    "author": "y",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "View3D ",
    "description": "2.Add a menu organized in 8",
    "warning": "",
    "support": "TESTING",
    "wiki_url": "",
    "tracker_url": "",
    "category": "User Interface"
import bpy
#Additional items in the edge menu
def draw_edge_item(self, context):
    layout = self.layout
    layout.separator() #Separator
    #Select an edge loop
    layout.operator("mesh.loop_multi_select", text="Edge Loops").ring = False
    #Select an edge ring
    layout.operator("mesh.loop_multi_select", text="Edge Rings").ring = True
#Additional items in the face menu
def draw_face_item(self, context):
    layout = self.layout
    layout.separator() #Separator
    layout.operator("mesh.flip_normals", text="Flip")
def register():
    #Add an item to the edge menu
    #Add item to face menu

def unregister():
    #Remove item from edge menu
    #Remove item from face menu

if __name__ == "__main__":

Add *** Edge Loop *** *** Edge Ring *** and *** Invert *** of Edge Menu to the menu.

Save to a file and specify and load the file from Install Add-ons in Preferences. Please note that since the support level is set to TEESTING, it will not appear in the list unless you select *** Testing *** on the tab above.

Steps to add your favorite items

Not limited to sample items, you may want to add menu items to your favorite menu. I will explain the procedure.

First, turn on the *** developer option *** in your preferences and change your workspace to *** Scripting *** image.png The parts related to the layout of Blender menus and panels are written in Python. By looking at this Python code, you can check the drawing commands of the menu, etc.

If you right-click a menu item etc. with the developer option turned on, an item called "Edit Source" has been added. When executed, the line of the click item of the Pyhton file that sets the UI will be displayed on the text editor. image.png (If you don't have a text editor in your workspace, you'll just get an error)

In this case, I tried to display the source of the *** mesh *** menu of *** mesh *** in edit mode ***. In the line with focus, the class for drawing the menu is called.

layout.menu("VIEW3D_MT_edit_%s" % edit_object.type.lower())

 I don't know what it is

 It is designed to change menu items depending on the object being edited
 (In this case, the object type is'MESH', and in this case .lower () is used as a lowercase'mesh' string)
 For the time being, I will search for the class starting with VIEW3D_MT_edit_ in the file.
 In this code, it seems that the process is written in the draw () function in the class that draws the contents of the menu from the 3559th line.
 Compared to the actual menu capture, for example

#### **`layout.menu("VIEW3D_MT_transform")`**

 Seems to display a submenu of *** Transform ***

 This time I want to use the contents of the *** normal *** submenu
 It looks like we should look further for the VIEW3D_MT_edit_mesh_normals class.
 I only wanted *** reversal *** this time

#### **`layout.operator("mesh.flip_normals", text="Flip")`**

It looks good only in the part of

After that, like the sample, create a function that specifies drawing similar to the draw () function of the class. Just append () the drawing function to the class of the menu item you want to register.

If you want to add menu items to your liking, please try this method as well.

Recommended Posts

Restore menu items that disappeared in Blender 2.8 or later
Blender 2.82 or later + python development environment notes
Add jinja2 filter in responder 2.0.0 or later