Page MenuHome

Is node collection ordered?
Closed, ArchivedPublic

Description

I actually have found that it is and it represents selection order. Probably it is worth mentioning in the documentation if it is going to be persistent between Blender releases?

https://docs.blender.org/api/current/bpy.types.Nodes.html

Event Timeline

Jacques Lucke (JacquesLucke) claimed this task.

Right, the nodes are ordered so that last selected node is at the end. This way it is drawn last, i.e. at the top. I don't really want to document this behavior though. I don't want anyone to rely on this order. See ED_node_sort for more details.

Well I was going to rely on it. I have the problem of determining of active output node of a group tree. There is tree.active_output attribute which looks doing nothing. It always (almost) points to last node in node collection (my guess). I think its purpose is to be corrected manually so it could point to any you like.

With assuming that nodes collection is order this task becomes simple I just have to find last output node in nodes collection. Otherwise I was thinking about adding draw handler to node tree to track nodes selection but I would like to avoid this solution if possible. Are you going to change this behavior soon?

You might be able to use the is_active_output property of output nodes. And yes, I think the active node is set by simply selecting the node. Since this node is also the active node, it will be moved to the back of the nodes list. So you can kinda depend on this fact for now, but I won't promise nor document that this won't change in a future release.

The tree.active_output selects the active output socket I think, not the active output node.