Execute node creation first, then create connections and groups.
(self)
| 107 | super().__init__(description, commands) |
| 108 | |
| 109 | def execute(self) -> bool: |
| 110 | """Execute node creation first, then create connections and groups.""" |
| 111 | # First execute node creation commands |
| 112 | if not super().execute(): |
| 113 | return False |
| 114 | |
| 115 | # Now create connections using actual pin objects |
| 116 | connections_data = self.clipboard_data.get('connections', []) |
| 117 | connection_commands = [] |
| 118 | |
| 119 | for conn_data in connections_data: |
| 120 | # Map old UUIDs to new UUIDs |
| 121 | old_output_node_id = conn_data.get('output_node_id', '') |
| 122 | old_input_node_id = conn_data.get('input_node_id', '') |
| 123 | |
| 124 | new_output_node_id = self.uuid_mapping.get(old_output_node_id) |
| 125 | new_input_node_id = self.uuid_mapping.get(old_input_node_id) |
| 126 | |
| 127 | # Only create connection if both nodes are being pasted |
| 128 | if new_output_node_id and new_input_node_id: |
| 129 | # Find the actual created nodes |
| 130 | output_node = self._find_node_by_id(new_output_node_id) |
| 131 | input_node = self._find_node_by_id(new_input_node_id) |
| 132 | |
| 133 | if output_node and input_node: |
| 134 | # Find pins by name |
| 135 | output_pin_name = conn_data.get('output_pin_name', '') |
| 136 | input_pin_name = conn_data.get('input_pin_name', '') |
| 137 | |
| 138 | output_pin = output_node.get_pin_by_name(output_pin_name) |
| 139 | input_pin = input_node.get_pin_by_name(input_pin_name) |
| 140 | |
| 141 | if output_pin and input_pin: |
| 142 | # Import here to avoid circular imports |
| 143 | from commands.connection_commands import CreateConnectionCommand |
| 144 | |
| 145 | conn_cmd = CreateConnectionCommand( |
| 146 | node_graph=self.node_graph, |
| 147 | output_pin=output_pin, |
| 148 | input_pin=input_pin |
| 149 | ) |
| 150 | connection_commands.append(conn_cmd) |
| 151 | |
| 152 | # Execute connection commands |
| 153 | for conn_cmd in connection_commands: |
| 154 | result = conn_cmd.execute() |
| 155 | if result: |
| 156 | conn_cmd._mark_executed() |
| 157 | self.commands.append(conn_cmd) |
| 158 | self.executed_commands.append(conn_cmd) |
| 159 | else: |
| 160 | print(f"Failed to create connection: {conn_cmd.get_description()}") |
| 161 | |
| 162 | # DEBUG: Check node positions before group processing |
| 163 | print("DEBUG: Node positions after creation, before group processing:") |
| 164 | for cmd, node_data in self.created_nodes: |
| 165 | if cmd.created_node: |
| 166 | pos = cmd.created_node.pos() |