Dynamo For Civil 3D Binding

Could someone explain to me element binding best practices for Dynamo in Civil 3D?

Clearly, if no binding data is retained, dynamo will recreate objects every time the script is run. However, dynamo will store binding data in the graph, in the drawing, and in the drawing for the player; what is the application for each of these options?

Say I have script that offsets a polyline. I want Dynamo to allow me to adjust the offset and not recreate the polyline every time the script is run and I want Dynamo to retain the link between the polyline and itā€™s offset even if I have to restart Civil 3D. Is this possible?

1 Like

Hi @mparks8G2XN,

This has been a point of confusion for a lot of folks for quite awhile, so letā€™s take the time to do a deep dive.

Hereā€™s an example. Iā€™m using Civil 3D 2023 with Dynamo Core 2.13. Below is the test graph, about as basic as you can get - create a circle on layer 0 at the model space origin.

(click to expand/collapse)

Case 1: No Binding Data Retained

image

Disconnecting/reconnecting input ports

If you disconnect and reconnect any of the ports on the Object.ByGeometry node, a brand new circle will be created every time.

Changing input values

Similar to disconnecting/reconnecting a port, a brand new circle will be created every time an input value is changed.

DYN file behavior

No binding data is saved in the .dyn file.

DWG file behavior

No binding data is stored in the DWG file.

Dynamo Player behavior

A new circle will be created every time the graph is run through Dynamo Player.

Summary

Use this setup if you want your Dynamo script to function similar to a LISP command, i.e. ā€œfire and forgetā€. You can use the .dyn on any drawing in any situation and it will create new objects every time.

Cases 2-4 below will all have the same behavior when disconnecting/reconnecting input ports and changing input values. The differences between them occurs when saving the graph, running the graph on different DWG files, and running the graph through Dynamo Player.

If you disconnect one of the ports on the Object.ByGeometry node, the circle will disappear from Model Space. If you reconnect the port, the circle will reappear. However, it technically isnā€™t the same circle that is reappearing. When you disconnect the port, the original circle is actually deleted, and then reconnecting the port creates a new circle. Itā€™s a subtle thing, but itā€™s important to understand because it could have implications if youā€™ve somehow linked other entities in the drawing to that original circle. Disconnecting/reconnecting the port would break those links.

Changing an input value (e.g. the layer name) doesnā€™t erase the circle and create a new one on a different layer. Instead, it will update the layer of the original circle, which is what you would expect to happen.

(click to expand/collapse)

Case 2: Store in Graph For Dynamo

image

DYN file behavior

If we save the graph, youā€™ll see in the .dyn file that there is a big nasty section for ā€œBindingsā€:

If you close/reopen the graph and run it on the same DWG, then everything should work the same as you left it. If you run the graph on a different DWG, then it will obviously create a new circle. However, as soon as you run the graph on the new DWG, the binding data will be removed from the .dyn file. This means that if you go back to the first drawing and run the graph again, a new circle will be created on top of the old one.

One more important thing to note here. Letā€™s say you save the .dyn and close Dynamo, and then modify the circle somehow, say move it to a new location. When you reopen and run the Dynamo graph, the circle will move back to where it was originally. This is important to understand because it could lead to unexpected results if other users arenā€™t aware that an object was originally created by Dynamo.

DWG file behavior

No binding data is stored in the DWG file.

Dynamo Player behavior

A new circle will be created every time the graph is run through Dynamo Player.

Summary

Use this setup if you want your Dynamo script to ā€œrememberā€ what stuff it created the last time it ran on a particular DWG. However, be aware that this only works if there is a one-to-one relationship between the DWG and the Dynamo graph. As soon as you start running a graph on multiple DWG files, youā€™ll lose this capability.

Case 3: Store in Drawing For Dynamo

image

DYN file behavior

No binding data is saved in the .dyn file.

DWG file behavior

Binding data is stored under-the-hood in what is called the Named Object Dictionary (or NOD). The dictionary is called DYNAMO_TRACE_DATA and looks very similar to that big nasty mess that gets saved in the .dyn file from Case 2. So if you close Dynamo and then reopen and run the same graph, then everything should work just how you left it. But hereā€™s the small difference with this mode versus saving the bindings in the graph: if you run the graph on a different DWG, the binding data is still preserved in the original DWG since it is saved in the drawing and not the graph.

Dynamo Player behavior

A new circle will be created every time the graph is run through Dynamo Player.

Summary

Use this setup if you want to use the same graph across multiple DWG files and have it ā€œrememberā€ what it did in each one.

Case 4: Store in Drawing For Dynamo Player

image

The first thing to note with this setting is that it really has no effect on how the graph interacts with the DWG when running the graph through the main Dynamo window. This setting only kicks into effect when the graph is run through Dynamo Player.

DYN file behavior

No binding data is saved in the .dyn file.

DWG file behavior

Like mentioned above, running this graph through the main Dynamo window will not result in any binding data being saved in the DWG.

Dynamo Player behavior

If you run the graph through Dynamo and then close out and run the same graph through Dynamo Player, it will create a second circle on top of the one created through Dynamo. However, once Dynamo Player has run through the graph once, it will write binding data under-the-hood in what is called the Named Object Dictionary (or NOD) of the DWG. The dictionary is called DYNAMO_TRACE_DATA and looks very similar to that big nasty mess that gets saved in the .dyn file from Case 2. So if you run the graph multiple times through Dynamo Player, it will update objects instead of creating new ones. If you run the graph through Dynamo Player on a different DWG, the binding data is still preserved in the original DWG since it is saved in the drawing and not the graph.

Summary

Use this setup if you want to use the same graph though Dynamo Player across multiple DWG files and have it ā€œrememberā€ what it did in each one.

Cases 2-4 can be combined, but Iā€™m not going to go through all of the permutations.

Recommendation

Personally, I think there are basically two main scenarios that you might want:

  1. You donā€™t want Dynamo to ā€œrememberā€ anything about what it has done previously and just create new stuff every time in runs, regardless of the DWG it is being used with. If this is true, then Case 1 is the way to go.

  2. You want Dynamo to ā€œrememberā€ everything about what it has done previously and use the same graph across multiple DWG files. You also want to be able to run the same graph through the main Dynamo window and/or Dynamo Player and have it keep track of objects in both scenarios. If this is true, then the combination of Cases 3 and 4 should work.

16 Likes

Thanks @mzjensen! Thatā€™s exactly the explanation Iā€™m looking for.

Wonā€™t this work in Civil3D 2022 ?

Yes. The only difference is that you need administrator access to change the binding settings. That was changed in 2023.

Thanks, mzjensen.
The version is 2022 in our company, so I canā€™t try it on 2023 yet.
Will the binding alternative in 2022 use the ā€œFunction.Applyā€ node as in the previous post?

Normally we recommend the user to have the settings set to case 3 and 4 because we have our graph set to Read Only when we deploy them.
But in special cases, such as in a project where the user want to add labels in to several Profile views but the inputs depends in a selection of block references along each Profile Views Alignment, they need to be able to run the graph several time in the same drawing and the element binding issue occurs.
My question is if we can use these nodes from C3D 2023
image

The thing is that I canā€™t make it work :frowning:

ORā€¦ Do I need to tell the user to set this manually when they run the specific graph and I have misunderstood to purpose of the nodes for ScriptBinding?

These nodes have no real use:

Personally I uncheck every binding setting, so that the binding is on while editing and finetuning the graph, but it is forgotten after reopening the graph or drawing.

In your case, the user should check the ā€˜No data binding retainedā€™ before running the graph over and over, or use the Player (and none of the binding options checked).

1 Like

Thanks for your answer @Anton_Huizinga
Even if itā€™s not perfect it work better now.

1 Like