[Bf-python] Proposal for getting identifier names for datablocks that require links to objects

Ken Hughes khughes at pacific.edu
Thu Sep 11 00:57:02 CEST 2008


I ran into something while looking at a bug report for the Particle API 
and thought I'd get some opinions here before implementing some 
hare-brained idea.

The proposal:

We implement a 
datatype/attribute/function/constructor/whatever-you-want-to-call-it for 
particles which contains all the names of existing particle datablocks.  
This can then be used as an argument to link an existing datablock to a 
object:

   names = bpy.data.particles  # returns a list of strings, not BPy 
particles
   if len(names) > 0: ob.newParticleSystem(names[0])

You could also add a system by name, assuming it exists (otherwise an 
exception is thrown):
   ob.newParticleSystem("PSys")

The background:

The new Particle API required that the BPY Particle object know which 
Blender object it's linked to (for example, Particle.getLoc() needs the 
object).  This is similar to what some BPy Mesh methods do (e.g, vertex 
groups, etc).  For this reason, I surmise, the Particle.Get() function 
wasn't implemented fully since more than one object can use the particle 
datablock.

I don't particularly want to implement Particle.Get() anyway since the 
last time we'd discussed redoing the API we wanted to move away from 
those type of functions and do thing more top-down where possible.

Anyway, without something like the .Get() function I don't see any way 
to link an existing particle system to an object; there's no way to get 
a specific particle system by name or a list of all the particle 
systems.  I personally don't like that there are meshes which do and 
don't have objects associated with them (doing "me = ob.getData(mesh=1)" 
versus "me = bpy.data.meshes['Cube']"); so I don't think we should 
replicate that style in the Particle API.

Ken



More information about the Bf-python mailing list