[Bf-python] unique identifiers for faces to use as dictionary keys

Toni Alatalo antont at kyperjokki.fi
Fri Oct 15 18:28:21 CEST 2004


On Fri, 15 Oct 2004, Tom Musgrove wrote:

not knowing about this really, am answering mostly 'cause no-one else has 
and had this thought:

> are there any unique identifiers for faces that can be used as keys?

#blendercoders:
<amino> I think there's no such thing yet in bpy

> I realize I could create a key by something like

could you perhaps use Python's built-in id() ?
that gives you the *runtime* -unique & persistent id of the object.

> for vert in faces.v:
>    id.append(vert.index)
> but I need something that I can access quickly,

do you need it to be consistent between several runs? these are probably
just what python assigns for the objects that the API gives, having no
relation to what may be in some internal Blender structure:

for face in me.faces:
    print id(face), hash(id)

i'm using Python object id's like this in some game engine apps.

of course, if the face object itself is hashable .. uh, it seems that 
id(face) and hash(face) are the same thing *embarrassed* (and updated that 
example)

so that's the same than using the face as the key directly,
yourdict[face] = yourthing 

> Tom M.

~Toni





More information about the Bf-python mailing list