Process/Addons/Guidelines/UpdatingScripts

From Blender Developer Wiki
Jump to: navigation, search

Updating Scripts from 2.7x

This page lists change you may need to make to your scripts so they run in 2.8x.

Module Registration

Module registration (bpy.utils.register_module) convenience function has been removed, since keeping track of this information adds unnecessary overhead.

Add-on's should assign their classes to a tuple or list and register/unregister them directly.

eg:

classes = (
    FooClass,
    BarClass,
    BazClass,
)

def register():
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)

def unregister():
    from bpy.utils import unregister_class
    for cls in reversed(classes):
        unregister_class(cls)

To avoid having to copy & paste the functions above, you can use bpy.utils.register_classes_factory utility function.

classes = (
    FooClass,
    BarClass,
    BazClass,
)
register, unregister = bpy.utils.register_classes_factory(classes)

If you have an addon with many classes, the list can be generated using this patch: https://developer.blender.org/P455

Class Registration

See T52599 for proposal and details.

Access (bpy.types)

Now only [Header, Menu, Operator, Panel, UIList] are accessed from bpy.types.

Generally scripts access classes they define by importing their own modules, so this should not impact many scripts.

Naming

In Blender2.7x it was too easy to accidentally register multiple classes with the same name.

To prevent collisions 2.8x enforces naming conventions (already in use across much of Blender's code-base)

This constraint applies to the bl_idname of each class (or the class name which is used if no bl_idname is defined in the class).

These are: UPPER_CASE_{SEPARATOR}_mixed_case, in the case of a menu the regular expression is:

   [A-Z][A-Z0-9_]*_MT_[A-Za-z0-9_]+

Each classes separator is listed below:

  • Header -> _HT_
  • Menu -> _MT_
  • Operator -> _OT_
  • Panel -> _PT_
  • UIList -> _UL_

Valid Examples:

  • OBJECT_OT_fancy_tool
  • SOME_HEADER_HT_my_header
  • PANEL123_PT_myPanel (lower case is preferred but mixed case is supported).

At time of writing names that don't conform to this convention will warn on startup. Eventually we will make this into an error, eg:

Warning: 'Oscurart Files Tools' doesn't contain '_PT_' with prefix & suffix
Warning: 'Oscurart Overrides' doesn't contain '_PT_' with prefix & suffix
Warning: 'Oscurart Animation Tools' doesn't contain '_PT_' with prefix & suffix

Scene Layer Access

TODO.

Object Selection Access

TODO.