fbpx
Lacing in Dynamo Explained

Data management is one of the most important concepts to understand when it comes to building Dynamo scripts. It’s extremely important to manage the data as it travels through the script in order to achieve desired results and avoid errors and warnings. Data matching is just a small part of this management concept. Data matching refers to how multiple sets of data that differ in length are handled by the code. In Dynamo, we have the ability to control this by changing the Lacing setting of a given node.

What is Lacing?

Lacing is a feature in Dynamo that allows you to control how lists of different lengths interact with each other. The Lacing mode dictates how one input connects to another input for a given node. There are four modes that you can set the node to: Automatic, Shortest, Longest and Cross Product. You can quickly see what the Lacing is set to by looking at the bottom right corner of the node.

automatic lacing

Automatic

shortest lacing

Shortest

longest lacing

Longest

cross product lacing

Cross Product

In order to help explain visually, I will refer to the example script below. In this script, I have used two sequences to generate lists of points. By using two different sequences, I can create lists of different lengths so that we can see how they interact when we modify the Lacing setting.

example dynamo script

Automatic/Shortest

When you place a node, you will notice that it is set to Automatic. This is another way of saying that the node is set to the default lacing mode, which is essentially the same as Shortest. Both modes will almost always result in the same output and therefore are commonly considered to be the same mode. The difference is in the way Shortest and Automatic are written out in the code under the hood of Dynamo. (More information on this can be found on the Dynamo GitHub.)

Shortest refers to the “Shortest List” algorithm. This is the simplest way to connect inputs. When Lacing is set to this mode, inputs are connected one-on-one until one of the lists runs out.

In the example script, I added the Line.ByStartPointEndPoint node and connected the outputs from both of the Point.ByCoordinates nodes (The lists of points) to the inputs of the Line.ByStartPointEndPoint node in order to draw lines from one point to another. As you can see, the Lacing for the node is set to Automatic by default and draws lines from the first point in the first list, to the first point in the second list, then the second point in the first list, to the second point in the second list, and so on, until all of the points from the shortest list have been connected to a point from the longer list. Notice that all of the points from the shorter list have lines drawn to them and that two points from the longer list do not have any lines drawn from them.

lacing node set to automatic

*Lacing for the Line.ByStartPointEndPoint node is set to Automatic.

If I change the Lacing mode for the Line.ByStartPointEndPoint node to Shortest, by right-clicking on the node, hovering over “Lacing”, and then clicking “Shortest,” you can see that the results are the same as they were when the Lacing was set to Automatic.

*Change the Lacing mode for a given node by right-clicking on it, hovering over “Lacing”, and clicking on the desired mode.

lacing set to shortest

*Lacing for the Line.ByStartPointEndPoint node is set to Shortest.

Longest

Longest refers to the “Longest List” algorithm. When set to this mode, Dynamo will continue to connect inputs one-on-one, reusing elements if necessary, until both lists run out. When it’s necessary for elements to be reused, Dynamo will simply reuse the last element from the shortest list for the remaining elements in the longer list.

When I set the Lacing for the Line.ByStartPointEndPoint node in the example to Longest, we see that all of the points from the shortest list have lines drawn to them just like before, but the two points that remained when the Lacing was set to Automatic and Shortest now have lines drawn to the last point from the shortest list and there are no points from either list that remain unconnected to another point.

lacing set to longest

*Lacing for the Line.ByStartPointEndPoint node is set to Longest.

Cross Product

Cross Product, as you might’ve guessed, refers to the “Cross Product” method, in which all possible connections between all elements of both lists are made. Simply put, each element from the first list is connected to each element of the second list.

When I set the Lacing for the Line.ByStartPointEndPoint node in the example script to Cross Product, we now see that every point in one list has a line drawn to it from every point in the other list. Notice that the lines are only drawn from one point in the first list to another point in the second list and that no points in the same list are connected.

lacing set to cross product

*Lacing for the Line.ByStartPointEndPoint node is set to Cross Product.

Conclusion

As you can see in the examples, changing the Lacing for a given node can drastically change the output of that node. But, understanding how Lacing affects the connection between lists, grants you the ability to control how multiple sets of data that are different in length are handled for a given node. Therefore, allowing you to better manage the data in your script. While data matching isn’t the entire iceberg that is data management, it is a very crucial part and understanding how to control it is a huge step towards mastering data management in Dynamo.

You may also like:

Contact Us

Newsletter