Newbie question about "listening" the outliner events

Hi folks

Im only write a bloody simple scripts for blender and not expirienced with API at all and because of that dont know what is possible and what is not.

Is that possible to create an addon which would be listening any events happened in outliner? As an example what is “event”:
“Event” - would be anything happened inside outliner, i.e. if we create a new collection, change the name of collection or add some object to any collection.
So in each case addon would automatically trigger some of its internal operator in some “events” happened in outliner.

1 Like

some of this you can do with the msgbus system, but it’s a fairly advanced topic so I wouldn’t necessarily recommend it as your first foray into Blender scripting.

3 Likes

Thanks i will try to ask GPT about it. His current way to achieve that was using a handle_collection_update(scene): which does exactly what i was wanted and trigger event each time something happened with collections.

1 Like

Well, shortly - this is not quite what you want to do.

Maybe I will be wrong in exact terms, but I’ll try to describe logic here. And maybe there is something I don’t know.

First of all outliner is not a primary tool here. It is a way to orginize and show data that lives in blender scene and operators that come out-of-box, which related to scene organization in some way.

It’s a window in a bulding on top off foundation called bpy.data.

Every time you do something in outliner - it goes through operators. Operator is kinda wrapper to what really happens under hood with bpy.data.

Creating new collection through outliner goes like this under hood :

import bpy
col = bpy.data.collections.new(name='Collection')
bpy.context.scene.collection.children.link(col)

Then depsgraph updates, UI redraws, and new collection appears in outliner. And operator returns if it could do or not the task: {‘FINISHED’} or {‘CANCELLED’}

So basically, you do not need to do something exactly in outliner. It is a consequence, not cause.

And there is no way, to catch operator source context AFAIK. So there is no way to listen to outliner, because the output is just - “redrawing completed”, because that’s what outliner does - simply redraws.


What you could do in this position are:

First, do not try automate all the stuff. Try to re-think how could it work out for you in a “click-the-button” way.

And second - is listen to data changes.

There are two options depend on your needs. First one - handlers. You have to have handler to store data before change and comparing with data after change to perform on exact what was changed. This way is for stuff like adding new data, or removing data.

The second one is for changed properties of already created data. As was mentioned above - msgbus. This one is for attributes like name, position, etc. This thing is adressed.


When which one to use?

If I want to put every new created object to collection by object’s data type - I would use handler.

If I want to color collection if it’s name matches pattern - I would use msgbus.


But!!! Be carefull with that. msdgbus is fine, but handlers (especially depsgraph) can be super heavy as depsgraph updates every click and every click you have to store and compare data. This is not the best practice of automating things in blender.


I hope this clears things up for you.

I would recommend go “click-the-button” to figure out how blender works. What are operators, what is context, what is data and so on… This topic is advanced, as was mentioned before…

3 Likes