connection fix from
@@ -1293,6 +1293,7 @@ class NodeGraph(QtCore.QObject):
# build the nodes.
nodes = {}
+ new_node_connections = {}
for n_id, n_data in data.get('nodes', {}).items():
identifier = n_data['type_']
node = self._node_factory.create_node_instance(identifier)
@@ -1318,21 +1319,27 @@ class NodeGraph(QtCore.QObject):
# build the connections.
for connection in data.get('connections', []):
nid, pname = connection.get('in', ('', ''))
- in_node = nodes.get(nid)
+ in_node = nodes.get(nid) or self.get_node_by_id(nid)
if not in_node:
continue
in_port = in_node.inputs().get(pname) if in_node else None
nid, pname = connection.get('out', ('', ''))
- out_node = nodes.get(nid)
+ out_node = nodes.get(nid) or self.get_node_by_id(nid)
if not out_node:
continue
out_port = out_node.outputs().get(pname) if out_node else None
if in_port and out_port:
+ # only connect if input port is not connected yet or input port
+ # can have multiple connections.
+ # important when duplicating nodes.
+ allow_connection = any([not in_port.model.connected_ports,
+ in_port.model.multi_connection])
+ if allow_connection:
self._undo_stack.push(PortConnectedCmd(in_port, out_port))
- node_objs = list(nodes.values())
+ node_objs = nodes.values()
if relative_pos:
self._viewer.move_nodes([n.view for n in node_objs])
[setattr(n.model, 'pos', n.view.xy_pos) for n in node_objs]
