Leonardo-Pike-Excell / node-arrange

Arrange Blender node trees with one click
https://extensions.blender.org/add-ons/node-arrange/
GNU General Public License v3.0
1 stars 0 forks source link

Can nodes be arranged in non-interactive way? #3

Closed vanous closed 1 month ago

vanous commented 1 month ago

Thank you for all the awesome work on this! If i provide list of nodes to the operator (or rather, to the modified class itself), do you know if the arrangement can happen even if the context.space_data.edit_tree is not available? I have modified the routine, removed the "selected" filter, but at this point it only arranges the nodes on x axis and i would like to know if it makes sense to spend more the time on it... if perhaps there isn't something which would prevent it to work in situation when the node editor is not open.

Here is the very slightly modified class, I just removed the variables declared as global. And here i use it.

Thank you so much for your time and expertise.

Leonardo-Pike-Excell commented 1 month ago

node_tree should work fine in place of context.space_data.edit_tree. But other things may cause issues:

  1. If nodes have been added to the node tree without the node editor open, node.dimensions will be wrong since it only gets evaluated on UI redraw.
  2. bpy.ops.transform.translate() may fail without the proper context. (If you know the node trees won’t have frames or locations far from (0, 0), this shouldn’t be a problem.)

I can’t think of anything else that could case issues, but there may be more gotchas relating to context and UI redraw.

vanous commented 1 month ago

These are very good insights, thank you very much!

vanous commented 1 month ago

OK, for any future reader - yes, the node.dimensions are not usable before the UI is ready. Providing generic dimensions provides a reasonable result:

image