If I print this:
print( bpy.data.collections['My Collection'].objects[:] )
... I get a list of the objects in the collection, but it's not an alphabetical list like the Outliner. It looks like the objects are ordered by the moment in which they were added to the collection.
What is the best way of reordering the data in the collection alphabetically so that is is identical to what is displayed in the Outliner?
Also, how can I do this while keeping the same Collection name?
I'm working on an addon that imports objects from a Kitbash Library in a different Blend file with collections for different types of objects. There's a collection for chains, another for cables, etc.
I have a modal operator that lets you scroll through the objects in the different categories and display one object at a time. Basically, I import the entire collection but I don't link it to the scene, I only link one object of index[i] which is controlled by the mouse scroll.
I know that mouse scrolling might not be suited for a kitbash library with tons of elements but I want to keep this feature for quick asses to user favorites at least and implement a visual library UI/panel similar to what is used in Decal Machine later.
For now, I want people to be able to customize the Kitbash Blend file directly, reorder the objects by renaming them, put in their own objects, etc. The problem is that if they add a new object and rename it so that it is first in a collection, for example, it won't actually be first when you run the scrolling operator, it will still be last because it was created and added last.
Basically, re-ordering elements in the outliner to their personal preference will do nothing when I access the collection with:
I figured the best solution was to make sure the collection data is ordered alphabetically at some point in time, maybe during startup somehow or when the modal operator is first ran.
If anyone has a better idea I wouldn't mind hearing it.