constructors (Re: [Bf-python] More Proposed API changes.)
Joseph Gilbert
jgilbert at tigr.ORG
Mon Mar 12 23:11:35 CET 2007
Toni Alatalo wrote:
> i'd prefer constructors over dataiterator.new s.
>
I've already suggested this on IRC. Classes should not be part of an
iterator, however. They can and should be created with tp_new and tp_init.
example:
m = Mesh(scn, "mesh1") #creates and adds to G.main
m = bpy.meshes['mesh1'] #attempts to query for this mesh in G.main
This allows the script writer to do
if isinstance(m, Mesh):
rather than having to check the type of an object with the 'Types' module
Campbell Barton wrote:
> having bpy.Group() and bpy.groups seems to over complicate things
> * A new or casual user has to remember that a slightly different word
> is used to make the data and another is used to loop on it..
Separate the class from the iterator. Group() and bpy.groups. If the
names are too similiar call bpy.groups something else.
> * ob = bpy.Mesh(scn, me) - is adding the mesh to scn, seems less logical.
Than what? bpy.scenes.active.meshes.add(me)
Make scn default to the active scene and you get the same effect.
Joe Eagar wrote:
> So if a user does, "mesh = bpy.Mesh()", is he going to realize that
> mesh is automatically added to bpy.meshes? What will he think, when
> he realizes it isn't garbaged collected?
This confuses the point. Calling a class constructor OR a factory
function will cause a datablock to be added to G.main. Garbage
collection occurs on wrapped instance of a class. This occurs in the
current api if i call "m = Mesh.new()" and m goes out of scope. m gets
deallocated but a new mesh is found in G.main.
Having been involved with this project for a long time I know where
suggestions end up, but i thought i'd speak up anyway.
More information about the Bf-python
mailing list