Page 1 of 1

Script to Alphabetically sort Browser

Unread postPosted: Thu Jan 28, 2021 12:52 am
by devinj898

Any chance someone has already made and would be willing to share, a Python script to alphabetized the far left section of the Browser? It would be very helpful to keep my project organized. That left panel always seems to get disorganized without me even realizing it, and I am having trouble keeping up with all the contexts not being sorted 0-9, then A-Z.


Re: Script to Alphabetically sort Browser

Unread postPosted: Tue Feb 02, 2021 4:01 pm
by anemoff

You should be able to reorder items in a context using the following API from OfContext:
Code: Select all
move_item_index(const unsigned int old_index, const unsigned int new_index) ... 6e6bcd2583

However this API modifies the project, it's not just a UI reordering, so you need to save the project after reordering.

You need to do the reindexing yourself.


Re: Script to Alphabetically sort Browser

Unread postPosted: Mon Feb 08, 2021 9:50 pm
by jboissinot

I was actually planning to ask about this, so I'm glad that it has been discussed already, and thanks for sharing a solution on how we could it.

I did some testing on my own to explore this but I noticed something wrong. In fact, let's say that I create 3 contexts, A, B, and C, in a context.
If I print the index of all contexts, I do get 0 for A, 1 for B, and 2 for C. However, if I rename A with D, then I'm getting index 1 for C while it should still be 2. Looks like it might return the creation index and not the display index. Maybe that's normal and expected actually, I just thought that find_item_index() would return the actual position of an item in a context.

Can you clarify this to make sure that what I assume makes sense or if it's a bug with the API?


Re: Script to Alphabetically sort Browser

Unread postPosted: Fri Feb 12, 2021 7:05 pm
by anemoff
I can confirm the following:
- renaming an item will reorder it and put it last
- the UI is not refreshed after renaming the item to reflect its new position (bug)

I used this little script to print the index of the selected items:

py code

for item in ix.selection:
if item.is_context():
print(item.get_name(), item.get_parent().find_item_index(item))
print(item.get_name(), item.get_context().find_item_index(item))

I will investigate some more next week.