NodeArrange
NodeArrange copied to clipboard
Dependency on `bpy.context.space_data` in `nodes_arrange` problematic in headless script
I'm trying to arrange node-trees (which are created through a Python script in bpy.data
in a UI-less blender) through functions from this addon.
This is my code:
def arrange(node_tree):
import node_arrange
f = 4
node_arrange.values.margin_x = 100 * f
node_arrange.values.margin_y = 80 * f
node_arrange.nodes_iterate(node_tree)
node_arrange.nodes_center(node_tree)
Unfortunately this code does not work because of this line depending on bpy.context
:
https://github.com/blender/blender-addons/blob/042c799b7aef9634a33d24e78d4922706aca9a2b/node_arrange.py#L403
This can be addressed, simply by modifying the signature of nodes_arrange(...)
so it receives an ntree
.
There is a single caller of this function where the ntree
is also already a local variable, so this is a trivial change.
(Having to modify node_arrange.values
instead of passing these options as parameter is also slightly annoying, but it's easy enough to keep a copy of the original values if need-be)
I'd have sent a patch upstream, but I don't have a developer.blender account, so I'd prefer if somebody else upstreamed it. Consider my change recommendation to be in public domain and fully compliant with the existing addon / blender license.