ikeough/Dynamo — pull request #855 by ambarish-prakash (2013-11-27 12:22:19+00:00)
Title: Node To Code Connections

How Does It Work :
---

During Node to Code, Each node is built into a set of AST Nodes and these nodes are converted back to Code. This Code is then used to create a Code Block Node.

Connections :
1. Removing the connections :
Each connection is deleted. However if it is an external connection (if one of the nodes it is connecting to does not lie inside the N2C selection), its details are first saved.
The details are here are the connector itself and the variable name that is generated when the node is built (as this will be the name of the variable in the built AST Nodes, and hence the name of the variable in the final code block node). The variable name is got by using the "GetASTIdentifierForOutportIndex" method of the NodeModel.
After the data is stored in a dictionary, the connector is then deleted.

2. Recreating the connections :
Using the list of old connectors, we can now create the new ones.
The external node and external port can be retrieved from the connector.
The internal new node will be the new Code Block Node, and the required port can be acquired from the variable name that was saved from before.