[Bf-committers] Auto-registration in Python
theeth at yahoo.com
Tue Nov 2 04:31:58 CET 2010
--- On Mon, 11/1/10, Matt Ebb <matt at mke3.net> wrote:
> From: Matt Ebb <matt at mke3.net>
> Subject: Re: [Bf-committers] Auto-registration in Python
> To: "bf-blender developers" <bf-committers at blender.org>
> Received: Monday, November 1, 2010, 10:58 PM
> On Tue, Nov 2, 2010 at 1:44 PM,
> Martin Poirier <theeth at yahoo.com>
> >> 4) dynamically defined classes/operators are also
> a case
> >> where auto-registration becomes more tricky then
> its worth.
> > If you're talking about the cases where people were
> using type() to initialize a class, that's very much
> overcomplicating things for nothing (even without automatic
> I've been using exec() to dynamically generate
> idpropertygroups with
> lists of parameters that are determined at runtime. How
> could this be
> done without dynamically defining classes?
bpy.types.Scene.new_property = PointerProperty(type=NewPropertyGroup, name="Stuff", description="Fun New Stuff")
NewPropertyGroup.name = StringProperty(
description="Name of something",
maxlen = 128,
default = "")
# and so on
This will define a new IDPropGroup every time the function is called.
The name of the class doesn't matter, it only keeps it for a limited time in its namespace anyway. You can do NewPropertyGroup.__name__ = "BOB" later if you want to change its internal name.
Not sure if that will work correctly at runtime (instead of at define time, when the module is imported), since registration is delayed by default, you might have to register it manually (a long term solution would be to switch the delay registration logic around to false by default and only true when importing addon modules).
More information about the Bf-committers