[Bf-python] Is is possible to link/append particle settings?

Michel Anders Michel.Anders at inter.nl.net
Mon Feb 17 19:20:22 CET 2014


Hi,

 

Currently I am working on enhancing my space tree addon and I want to link
or append particle settings from a bundled library.

 

Now bpy.data.libraries.load() works fine but the objects returned in by the
context manager do NOT expose a particles attribute so I am forced to link
the object with the associated particle system and get the particlesettings
as side effect. This is not so desirable because I have no need for the
object itself. (see code below)

 

Am I missing something here/could this be done more elegantly or is not
having a .particles attribute an omission in the API perhaps?

 

 

Thnx,

 

-- Michel (varkenvarken).

 

def load_particlesettings(library, object_name, settings):

    beforep = set(m.name for m in bpy.data.particles)

    before  = set(m.name for m in bpy.data.objects)

    with bpy.data.libraries.load(library) as (data_from, data_to):

        data_to.objects = [m for m in data_from.objects if m == object_name]

    afterp = set(m.name for m in bpy.data.particles)

    after = set(m.name for m in bpy.data.objects)

    new = after - before

    if len(new) != 1:

        raise ValueError("While loading object %s from library %s %d objects
were found (%s) instead of just 1"%(

            object_name,library,len(new),str(new)))

    new = afterp - beforep

    if len(new) != 1:

        raise ValueError("While loading particle setting %s from object %s
in library %s %d objects were found (%s) instead of just
1"%(settings,object_name,library,len(new),str(new)))

    return bpy.data.particles[new.pop()]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20140217/8bb78e71/attachment.html>


More information about the Bf-python mailing list