0
$\begingroup$

So i'm working on a addon.

  • I'm creating Collections in the process and this collections (name) are store in enum ( so the user can load and unload it ).
  • I'm using collection name to find the collection, but if the user change it it wont work anymore.
  • So i could create an attribute on this collection, like : {addonname : Collection Name}
  • But that mean every time I'm loading the addon ( or every time the user is changing the name of a collection ) I had to check on all collections in blend file to refresh my enum. That's feel dirty to me.

The Question is : Is there an other way to reference a collection ? (I'm still new to python and Blender so there is probably things I don't think of )

$\endgroup$
3
  • $\begingroup$ bpy.props.PointerProperty(type=bpy.types.Collection) ? $\endgroup$
    – Gorgious
    Commented Apr 4, 2022 at 17:50
  • $\begingroup$ I'm not sure to follow ? You're suggesting to use a PropertyGroup on a collections ? But if i create a this , all my collection will have a PointerProperty right ? then how can i find without looping into all of them which one is the one ? $\endgroup$
    – Zhaie
    Commented Apr 4, 2022 at 18:35
  • $\begingroup$ Unless you have hundreds of collections, looping over all the collections in a file isn't really computationally significant, and if you have hundreds of collections chances are the bottleneck will not be looping over them. It may seem dumb but that's often the way to go. They're stored in dictionary data structures meaning access is pretty fast all things considered $\endgroup$
    – Gorgious
    Commented Apr 4, 2022 at 19:04

1 Answer 1

0
$\begingroup$

In Blender 3.1, my solution is to create a string property on my special collections.

  1. Loop into all collection of the scene searching for the Property and Value

  2. The Value is an encoded key, so the user is not suppose to touch it but he can change the name of the object / collection / special item.

I have lot's of collections in my tools, but I'm make sure that I clean the unused ones and store data into json (to be able to call them back if needed).

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .