I'm currently working on a project-specific addon where I'm dynamically loading and removing images on the fly.

So far I've gotten away with a simple Image.isProjectProperty, but I now need an (ordered) list of these dynamically loaded images. However, a CollectionProperty with a type of BlendDataImages seems to be out of the question, and there doesn't appear to be a StringVectorProperty to store the names in either.

I could probably sort a temporary list, then find their bpy.data.images[] indices and store those in an IntVectorProperty, but that doesn't seem very safe either; what if 0-user images get removed between sessions? Is there a better way of going about this? What am I missing?

| improve this question | | | | |

If you need multiple strings, why not use CollectionProperty? bpy.types.PropertyGroup comes with a StringProperty already (name), then just add new items to the collection and assign an image's name.

*VectorPropertys shouldn't be used if the amount of integers, bools or floats aren't limited conceptually. They are meant to store things like transformation matrices, which are never larger than 4x4.

Since image datablocks are ID types, why don't you add an IntProperty and assign a number, then sort images by that? Set the default to -1, and ignore these to distinguish unrelated images from your project images:

import bpy

# Register property - should be in register()
bpy.types.Image.project_id = bpy.props.IntProperty(

# Assign number
img.project_id = ...

# Filter and sort
sorted(filter(lambda x: x.project_id > -1, bpy.data.images), key=lambda x: x.project_id)
| improve this answer | | | | |
  • $\begingroup$ The problem with using a CollectionProperty is that I need a different amount of names each time (one for each image loaded at the time). Assigning an id could work, but then I would still need to iterate through all images and sort them every single time I need them. An alternative I though of would be to load all images using a naming convention, like __ProjectImage1, which would work, but doesn't seem like the best solution either. $\endgroup$ – Senshi Nov 10 '14 at 16:15
  • $\begingroup$ Nevermind, I'm just being an idiot. ;) I'm using another framework at the moment and had the wrong idea of a CollectionProperty in mind. Thanks! $\endgroup$ – Senshi Nov 10 '14 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.