[Bf-python] Adding a new way to deal with libraries

Campbell Barton cbarton at metavr.com
Sat Mar 10 15:37:49 CET 2007


Martin Poirier wrote:
> --- Campbell Barton <cbarton at metavr.com> wrote:
> 
>> For now Ill assume "bpy" is acceptable and move
>> on... we can of course 
>> change, as with any part of the new API parts.
>>
>> next step is to deciede how library data could be
>> delt with.
>>
>> Id like to replace Blender.Library with somthing a
>> bit less messy.
>>   Im not sure they fit into the libdata
>> iterator-like way of working
>>
>> heres an example of how it might work..
>> ob =
>>
> bpy.libraries['//mylib.blend'].objects.link("somedata")
>> # '//mylib.blend' - could be a new or used lib, if
>> its new it would be 
>> added to bpy.libraries
> 
> For library access, I strong recommend moving away
> from the Open->Load->Close scheme that is/was used in
> Blender.Library. Using atomic operations (which seems
> to be what you are suggesting) solves a lot of
> potential problems (lib loading in Blender is a bit
> magic/messy).
> 
> Martin

Yep, and your right, this has to be written over Blenders alredy messy 
library handeling.

Im 80% sold on wrapping libraries with a new custom PyType (iterator).


The example I gave above wasnt that good because all the functionality 
happened on 1 line.

bpy.libraries # are a list/seq of libraries blender uses, [] by default.

# One of the 2 syntax's below could be used to add a new library.
lib = bpy.libraries.load('//mylib.blend')
lib = bpy.libraries['//mylib.blend'] # could create on demand...

.load() is probably more correct

it may be that we have deal with 2 sets of lib data - data thats 
currently in blender (as accessed by the outliner) - and data that use 
scripter has loaded, but is yet to be used by blender. I think thats ok. 
if its not used then it wont be there next time blender is loaded.

each lib from libraries can be its own pyType thats only stores a 
filename, and has attributes for accessing data withing the blend file.

for ob in lib.objects: could be an list/iterator of strings.

ob = lib.object.link(obname)

could load the object into blender and return the python object.


so say you want a group called 'mygroup'


lib = bpy.libraries.load('//someblend.blend')
group = lib.groups.link('mygroup')


again, the logic is a bit weired, because were linking to bpy.groups 
from lib.groups, runnig this command on the source is odd.


maybe it would be more logical to run the add command from.
grp = bpy.groups.link('mygroup', '//mylib.blend')

and keep lib.groups just a list of names

- any thaights?























More information about the Bf-python mailing list