[Python Scripting] Transitioning from Blender 2.7x to 2.8x

Greetings,

Long time no see! I haven't used Blender in a long time (2.71) and now I find myself in a place where I want to prototype something by scripting an add on. I'm finding this is a bit of a piecemeal slog. I did find this link that addresses breaking changes from 2.7x to 2.8x.

https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API/Addons

Has anyone found other specific gotchyas when approach scripting in the latest and greatest Blender? ddbrown perhaps? (Hi!) I guess I tell myself to expect other surprises because of UI changes, but maybe that didn't change so much from an API perspective :shrug:

Thanks!

  • Ryan Sweeney(sweenist) replied

    Ah fun! Discovered that `INFO_MT_mesh_add` was replaced with `VIEW3D_MT_mesh_add` when adding an item to the mesh menu. Couldn't find documentation on this but at least the templates in the text editor are up to date.


    So old code for registering a module now changes to adding a class.
    Old way:

    def register():
        bpy.utils.register_module(__name__)
        bpy.types.INFO_MT_mesh_add.append(menu_func)
        
    def unregister():
        bpy.utils.unregister_module(__name__)
        bpy.types.INFO_MT_mesh_add.remove(menu_func)
    


    New Way:

    def register():
        from bpy.utils import register_class
        register_class(ClassName)
        bpy.types.VIEW3D_MT_mesh_add.append(menu_func)
    
    
    def unregister():
        from bpy.utils import unregister_class
        unregister_class(ClassName)
        bpy.types.VIEW3D_MT_mesh_add.remove(menu_func)