PROBABLYBUG: Objects are not added respecting their order in the Blender Outliner
KirilStrezikozin opened this issue · 1 comments
This bug report is:
- not a duplicate
- fixed
Describe the bug
When multiple objects are added to BakeMaster, they do not follow the order they had in Blender Outliner.
To Reproduce
Steps to reproduce the behavior:
- Select several objects.
- Click on 'Add' in BakeMaster.
- The order of objects in BakeMaster is not the same as in the Outliner.
Expected behavior
Should the order of objects be preserved?
Screenshots
1a. Order in the Outliner:
1b. Order in BakeMaster:
The reason probably is
BakeMaster respects the alphabetical order of Meshes:
The behavior of the following case is unknown:
2a. Order in the Outliner:
2b. Order in BakeMaster:
Desktop (please complete the following information):
- OS: Windows
- OS Version: Windows 11
- Blender Version: 4.0.0
- BakeMaster Version: 2.6.0a3
Additional context
Found and reported by @KirilStrezikozin.
Investigating the reason
- Using the meshes listed in behavior 2a above, the built-in
bpy.context.selected_objects
contains objects of order put into BakeMaster (BakeMaster itself does not contain any order manipulations unless name matching is used):
# Console input:
>>> C.selected_objects
# Console Output:
[
bpy.data.objects['Circle'],
bpy.data.objects['Sphere'],
bpy.data.objects['Plane'],
bpy.data.objects['Torus']
]
- The type of
bpy.context.selected_objects
is<class 'list'>
. Lists are ordered:
assert type(C.selected_objects) == list
-
It is noticeable that the order of objects in
bpy.context.selected_objects
is the order they were edited to a scene. Thus, a conclusion is that BakeMaster adds objects from Blender Outliner in the order these objects were added to a Blender scene in the first place. -
Blender Outliner has an Alphabetic Sorting option that is defined in each Outliner area.
Solution
Introduce a property in BakeMaster Addon Preferences The best idea is to adapt to each situation. Every time the BakeMaster Object Add operator is called (and name matching is not used), find the first Outliner area in the current screen. If it has alphabetic object sorting, add selected objects to BakeMaster via:
sorted(C.selected_objects, key=lambda x: x.name)
If it doesn't have alphabetic sorting, plain add objects to BakeMaster. Overall, this way BakeMaster adds objects in the order they are in the Outliner, which makes it more convenient and visually appealing to the user.