defget_nodes_links(context):# Taken from Node Efficiency Tools by Bartek Skorupa
space=context.space_data
tree=space.node_tree
nodes=tree.nodes
links=tree.links
active=nodes.active
context_active=context.active_node
# check if we are working on regular node tree or node group is currently edited.
# if group is edited - active node of space_tree is the group
# if context.active_node != space active node - it means that the group is being edited.
# in such case we set "nodes" to be nodes of this group, "links" to be links of this group
# if context.active_node == space.active_node it means that we are not currently editing group
is_main_tree=True
ifactive:
is_main_tree=context_active==active
ifnotis_main_tree:# if group is currently edited
tree=active.node_tree
nodes=tree.nodes
links=tree.links
all_nodes=nodes
ifcontext.scene.SelectionOnly:
newnodes=[]
fornodeinnodes:
ifnode.select==True:
newnodes.append(node)
nodes=newnodes
iflen(nodes)==0andcontext.scene.SelectionOnly:
nodes=all_nodes
nodes_sorted=sorted(nodes,key=lambdax:x.name)# Sort the nodes list to achieve consistent
links_sorted=sorted(links,key=lambdax:x.from_node.name)# results (order was changed based on selection).
returnnodes_sorted,links_sorted
defisStartNode(node):
bool=True
iflen(node.inputs):
forinputinnode.inputs:
ifinput.links!=():
bool=False
returnbool
defisEndNode(node):
bool=True
iflen(node.outputs):
foroutputinnode.outputs:
ifoutput.links!=():
bool=False
returnbool
defbetween(b1,a,b2):
# b1 MUST be smaller than b2!
bool=False
ifa>=b1anda<=b2:
bool=True
returnbool
defoverlaps(node1,node2):
dim1x=node1.dimensions.x
dim1y=node1.dimensions.y
dim2x=node2.dimensions.x
dim2y=node2.dimensions.y
boolx=False
booly=False
boolboth=False
# check for x overlap
ifbetween(node2.location.x,node1.location.x,(node2.location.x+dim2x))orbetween(node2.location.x,(node1.location.x+dim1x),(node2.location.x+dim2x)):#if either edges are inside the second node
boolx=True
ifbetween(node1.location.x,node2.location.x,node1.location.x+dim1x)andbetween(node1.location.x,(node2.location.x+dim2x),node1.location.x+dim1x):#if each edge is on either side of the second node
description="Delete all Reroute nodes to avoid unexpected layouts")
bpy.types.Scene.ImageType=bpy.props.EnumProperty(
name="Image Type",
items=(("render","Render","Use the render size to calculate Zoom Fit"),("image","Image","Use a specific image's size to calculate Zoom Fit"),("custom","Custom","Use custom dimensions to calculate Zoom Fit")),
default='render',
description="Which dimensions to calculate Zoom Fit from")