On Thursday, August 18, 2016 at 2:36:31 PM UTC+12, I wrote: > Solution: set up a table of rules ...
Here <https://github.com/ldo/render-useful/blob/master/ext-files> is another example. The problem is to list all external file dependencies of a Blender document, to ensure that they exist etc. Currently, as far as I know, these external files might be fonts, images, libraries (additional Blender documents containing linked assets) and sounds. The processing for all of these is very similar. But within some categories, there are special cases for items which need to be ignored. So my loop starts like this: for \ category, match, mismatch, extra \ in \ ( ("fonts", {}, (("filepath" , "<builtin>"),), ()), ("images", {"type" : "IMAGE"}, (), ("filepath_raw",)), ("libraries", {}, (), ()), ("sounds", {}, (), ()), ) \ : ... where “match” is a dictionary where each key is an attribute name, and the value is the corresponding value that the attribute must have, while “mismatch” is a tuple of (key, value) 2-tuples, where each “key” is an attribute name, and “value” is a value that attribute must *not* have. The table is designed so that I can easily add new categories, and new criteria for each category, as I discover them in future. So, within the above category loop, I loop over all items in the Blender document within that category that match the specified criteria: for item in getattr(bpy.data, category) : if ( item.packed_file == None and not any(getattr(item, k) == v for k, v in mismatch) and all(getattr(item, k) == match[k] for k in match) ) : That additional “item.packed_file == None” check indicates that the object is not stored in the .blend file, but resides in an external file. That, at least, is a common characteristic of all object categories (so far...). -- https://mail.python.org/mailman/listinfo/python-list