I am trying to generate dynamically operator classes.
The code below is based on the code at the end of this link
cls.CustomOp = []
for i in ['a', 'b']:
idname = "object.operator_" + i
def func(self, context):
print("Hello World", self.bl_idname)
return {'FINISHED'}
opclass = type("DynOp" + i,
(bpy.types.Operator, ),
{"bl_idname": idname, "bl_label": "Test", "execute": func},
)
bpy.utils.register_class(opclass)
cls.CustomOp = cls.CustomOp + [opclass]
I have tried the code above in poll and draw contexts, but always the same :
"RuntimeError: register_class(...): can't run in readonly state 'DynOpa'".
What does readonly context mean? How to do it (and from where) in a non-readonly context?