[Bf-python] Blender Datablocks. was Blender.Group

Campbell Barton cbarton at metavr.com
Sun Mar 19 02:27:48 CET 2006


Recently was thinking about Get/Unlink/New operations for datablocks and 
how they could be unified and operated on like a dict, where ID names 
are the unique keys.
This would be modified for the new Python API.

# Here are some examples using group. But they apply to all other 
Modules if this is implemented as a generic way of accessing data.

# Get a spesific datablock.
from: gp= Blender.Group.Get("mygroup")
to:     gp= Blender.Group.groups["mygroup"]

# Get all datablocks
from: gp= Blender.Group.Get()
to:     gp= Blender.Group.groups.values()

# New Datablock
from: gp= Blender.Group.New()
to:     Blender.Group.groups["mygroup"]= None
...      gp= Blender.Group.groups["mygroup"]
* Note that assigning None is kind of a crufty way to start a new group, 
however it allows for a nice way to copy datablocks, which is currently 
not supported.

# Copy datablock
  Blender.Group.groups["mygroup"]= orig_group
  copy_group= Blender.Group.groups["mygroup"]

# Unlink- only support for some datablocks
from: Blender.Group.Unlink(gp)
to:     del Blender.Group.groups[gp.name]


# Other dict access could be supported,
Blender.Group.groups.keys() # Get all group names, nice in its self. 
support iterkeys too.
Blender.Group.groups.items()  # (idname, data)
Blender.Group.groups.has_key("GroupName")

# Dont support clear,pop, popitem, setdefault, update


Some more thoughts....
Do we need Blender.Group.groups??
Couldn't we just access Blender.Group["someGroup"]??

Note this has nothing todo with sets :)

- Cam





Toni Alatalo wrote:
> On Friday 17 March 2006 01:39, Ken Hughes wrote:
>   
>>>> I was thinking the other day that maybe the Set
>>>> Protocol would be a good compromise in handling bitmask flags in Blender.
>>>>         
>> But I thought what Cam was proposing here was
>> to implement a custom BPy set class/object?  In fact,
>>     
>
> i originally thought of Blender.Groups as sets, when first heard about them a 
> few months ago. that is why i reacted to Cam's post recalling those thougts.
>
> a couple of days afterwards, yesterday i think, i realized that the usage we 
> have actually had for Groups in the Elephants Dream is not like Sets at all.
>
> many of our groups are more like compound objects, like Meta strips in the 
> sequencer of Group nodes in the node editor - e.g. a wall in a room can be a 
> group. it does not really make sense to be able to do set operations on a 
> compound object (e.g. walls in a room dont usually have overlap in members, 
> but well) .. but perhaps there are other uses for groups where set operations 
> are useful, dunno.
>
> anyhow, after that thinking, it was interesting to hear that Ken had another 
> idea.
>
>   
>> why not implement this for Blender versions based on
>> Python 2.3 and let versions based on 2.4 use the
>> built-in set class?
>>     
>
> dunno.
>
>   
>> Ken
>>     
>
> ~Toni
> _______________________________________________
> Bf-python mailing list
> Bf-python at projects.blender.org
> http://projects.blender.org/mailman/listinfo/bf-python
>
>   


-- 
Campbell J Barton

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241



More information about the Bf-python mailing list