--- On Mon, 11/1/10, Matt Ebb <m...@mke3.net> wrote:

> From: Matt Ebb <m...@mke3.net>
> Subject: Re: [Bf-committers] Auto-registration in Python
> To: "bf-blender developers" <bf-committers@blender.org>
> Received: Monday, November 1, 2010, 10:58 PM
> On Tue, Nov 2, 2010 at 1:44 PM,
> Martin Poirier <the...@yahoo.com>
> wrote:
> 
> >> 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
> registration).
> 
> 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?

-----

def fun():
  class NewPropertyGroup(bpy.types.IDPropertyGroup):
    pass

  bpy.types.Scene.new_property = PointerProperty(type=NewPropertyGroup, 
name="Stuff", description="Fun New Stuff")
    
  NewPropertyGroup.name = StringProperty(
                  name="Name",
                  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).

Martin


_______________________________________________
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers

Reply via email to