2
$\begingroup$

I would like to start developing in the new beta build environment. For that, I want to register classes the new way: https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API/Addons

However, I get the following error:

TypeError: 'type' object is not iterable

Also, when trying "help(bpy.utils.register_class_factory())" in the inteactive python console, I get:

AttributeError: module 'bpy.utils' has no attribute 'register_class_factory'

Some simplified code I am "working" on right now:

import bpy

class MakeProxy(bpy.types.Operator):
    bl_idname = "OBJECT_OT_object_make_proxy"
    bl_label = "mProxy"

    "more code"

classes = (
    MakeProxy
    )

register, unregister = bpy.utils.register_classes_factory(classes)

What am I missing? Thank you!

$\endgroup$

1 Answer 1

2
$\begingroup$
import bpy

class OBJECT_OT_object_make_proxy(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.make_proxy"
    bl_label = "Make Proxy"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        pass # More code here
        return {'FINISHED'}

classes = (
            OBJECT_OT_object_make_proxy,

          )

register, unregister = bpy.utils.register_classes_factory(classes)


if __name__ == "__main__":
    register()

This works.

I do not understand what they mean to say about the new naming conventions here. Browsing the web it seems I am not the only one.

It says:

This constraint applies to the bl_idname of each class (or the class name which uses it 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_]+

The separator for each class 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 the time of writing this, names that don't conform to this convention will produce a warning 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

So this might mean that the bl_idname should actually be something like "object.MY_ADDON_OT_some_object_operator" It still requires a '.' to be there so object.OBJECT_OT_something_something does not seem to make much sense to me. Let's make this a new question as well, maybe someone else knows.

$\endgroup$
3
  • $\begingroup$ Okay, although I dont yet onehundred percent understand why it works, it does not throw any errors on compilation anymore. I am hoping for more clarification in the other question. However: I am not able to call my function from the "spacebar - search - window", as I was able to in 2.79. Any thoughts on that, maybe? Please? :) $\endgroup$
    – morph3us
    Dec 2, 2018 at 14:58
  • $\begingroup$ The way I understand it, what was wrong in your script were two things: bl_idname requires a '.' character to be in it, and the arguement for bpy.utils.register_classes_factory() needs to be iterable, so you need a comma after the value you assign to it or to make it a list first you could do classes = list() followed by classes.append(some_single_class) if you wanted a list with a single element. If you search for what you have in bl_label while poll() returns true, you should find the operator with the search. $\endgroup$ Dec 2, 2018 at 15:22
  • $\begingroup$ Yes, you are right, I just copied your exact script, rather than just trying to fix mine and yours works. So I am doing something wrong, obviously. Thank you so much for your time! $\endgroup$
    – morph3us
    Dec 2, 2018 at 15:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .