Page MenuHome

'users of ID' API (from id-remap).

Authored by Bastien Montagne (mont29) on Dec 18 2015, 11:47 PM.



This adds iterator over all (ID) users of a given datablock.
Mostly handy through the associated RNA API.

Note that it also had to fix an issue with RNA using DNA's ListBase struct (this
works OK with py, but breaks with cpp due to missing include - and we do not want to have to
include a DNA header just for that ;) ).

Diff Detail

rB Blender

Event Timeline

Bastien Montagne (mont29) retitled this revision from to 'users of ID' API (from id-remap)..Dec 18 2015, 11:47 PM
Bastien Montagne (mont29) updated this object.
Bastien Montagne (mont29) updated this revision to Diff 5586.
288–292 ↗(On Diff #5586)

This RNA fix will be committed separately of course, but would not mind a second advice on it before it goes to master.


Not really happy with the names of those funcs, open to better suggestions! :)

Updated against lastest master.

Updated against latest master...

  • Merge branch 'master' into tmp-id-users

Main concern with this patch is script authors are likely to call this in a loop, which ends up being a really expensive operation and easily ends up in situations where script authors can do entire Main data-base searches for every object/mesh/material... without understanding what they do.
Further, the kinds of situations I've seen this used are when dealing with many objects (exporting entire selection... or scene).

Exposing this in C with some warning to use with care, could be ok... but for Python I think its better to support this in a way that wont have such a performance hit and encourages smarter use.

eg, we could have:

user_map =
for obj in

If needed, it could take a subset of objects (to save the hassles of creating a very large map when only a few objects are needed).

objects = context.selected 
user_map =
for obj in objects:
Bastien Montagne (mont29) updated this revision to Diff 5742.
  • Move Py-side of 'users of ID' from rna to bpy.
26–31 ↗(On Diff #5742)

from old file.

128 ↗(On Diff #5742)

args are assured to be a typle, so no need to use an iterator, just call PyTuple_GET_ITEM / PyTuple_GET_SIZE

However, think this isnt so good practice since it will make extending this later into a pain (can be done with keyword only args, but still...).


All data:

Some data:
.user_map(subset=(ob1, ob2, ob3))

Then later we can add other restrictions...

.user_map(subset=(ob1, ob2, ob3), library=mylib)

And in this case it could be any sequence, so use PySequence_Fast / PySequence_Fast_ITEMS - so we can still have fast array access.

  • Avoid re-creating a pyobject for each and every ID just to check dict key.
  • Address suggestions and comments from review.
  • Merge branch 'master' into tmp-id-users
This revision was automatically updated to reflect the committed changes.