Is it possible to detect changes in object and collection selections or activations (bpy.context.object/collection)? I'm most interested in detecting changes in the active object and active collection.

If there currently is no way to receive events for selection or active object changes, what is best practice for setting up a looping processing function for an add-on? Would I need to add some type of timer? Or is there a handler that would work good for this?

My intention is to figure out which type of object was activated most recently - a collection or an object, so I can draw controls that relate to that object type. I'm currently just drawing both, but it takes up a lot of space.

Is there possibly some type of "activation_time_stamp"? Or anything that would help?

  • 1
    $\begingroup$ Is there anything stopping you from checking what the selected object is in the draw function of the panel? That function is executed whenever the UI is drawn, therefore you don't need another callback or handler. $\endgroup$ – Robert Gützkow Sep 13 at 20:45
  • $\begingroup$ I can figure out what is active and what is selected, but I have no way of knowing which one the user activated last. So if I have different controls to manipulate both collections and objects, but I only want to show one of those sets of controls at a given time, I have no way of knowing which the user is wanting to manipulate (collection or object). Unless there is a state somewhere that one could use as a hint, like a previous active object state. That's what I was trying to incorporate, but I would need some type of processing loop to do so. $\endgroup$ – Robert Sep 13 at 21:13
  • $\begingroup$ Then that's a design problem of your add-on. There is nothing wrong with adding two sub-panels one for the active object and one for the active collection. This gives the user the option to collapse the sub-panel if it's not needed. Trying to create a handler that monitors every selection change just to hide a panel doesn't sound like a good idea. $\endgroup$ – Robert Gützkow Sep 13 at 22:24
  • $\begingroup$ Right, that's what I have now. I was just hoping to make it cleaner/simpler by showing options for whatever the user is dealing with at the moment. Collapsing panels wouldn't be ideal in this situation because the user would likely be constantly switching between the two types of objects. But I doubt I will create a processing function or timer just to make it happen, because even with the timer, it would feel like a hack. Perhaps there is some way to detect the "active outliner item"? That would be ideal. $\endgroup$ – Robert Sep 13 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.