2012-06-11 10:11:31 +00:00
|
|
|
import bpy
|
|
|
|
|
2012-06-11 12:13:41 +00:00
|
|
|
|
2012-07-03 21:03:39 +00:00
|
|
|
def main(context):
|
2012-06-11 10:11:31 +00:00
|
|
|
space = context.space_data
|
|
|
|
node_tree = space.node_tree
|
|
|
|
node_active = context.active_node
|
|
|
|
node_selected = context.selected_nodes
|
|
|
|
|
|
|
|
# now we have the context, perform a simple operation
|
|
|
|
if node_active in node_selected:
|
|
|
|
node_selected.remove(node_active)
|
|
|
|
if len(node_selected) != 1:
|
|
|
|
operator.report({'ERROR'}, "2 nodes must be selected")
|
|
|
|
return
|
|
|
|
|
|
|
|
node_other, = node_selected
|
2012-06-11 12:13:41 +00:00
|
|
|
|
2012-06-11 10:11:31 +00:00
|
|
|
# now we have 2 nodes to operate on
|
|
|
|
if not node_active.inputs:
|
|
|
|
operator.report({'ERROR'}, "Active node has no inputs")
|
|
|
|
return
|
|
|
|
|
|
|
|
if not node_other.outputs:
|
|
|
|
operator.report({'ERROR'}, "Selected node has no outputs")
|
|
|
|
return
|
|
|
|
|
|
|
|
socket_in = node_active.inputs[0]
|
|
|
|
socket_out = node_other.outputs[0]
|
|
|
|
|
|
|
|
# add a link between the two nodes
|
|
|
|
node_link = node_tree.links.new(socket_in, socket_out)
|
|
|
|
|
|
|
|
|
|
|
|
class NodeOperator(bpy.types.Operator):
|
2012-07-01 07:55:44 +00:00
|
|
|
"""Tooltip"""
|
2012-06-11 10:11:31 +00:00
|
|
|
bl_idname = "node.simple_operator"
|
|
|
|
bl_label = "Simple Node Operator"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
space = context.space_data
|
|
|
|
return space.type == 'NODE_EDITOR'
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
main(context)
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
|
|
def register():
|
|
|
|
bpy.utils.register_class(NodeOperator)
|
|
|
|
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
bpy.utils.unregister_class(NodeOperator)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
register()
|