Dynamo allows programming without coding



15 Dec 2021

By: Andrew G. Roe



CAD Programming: Dynamo, Part 1. Creating Objects in Civil 3D and Revit.

In previous articles, we looked at various programming and customization options for CAD products. In this article, we’ll explore a newcomer to the CAD programming scene: Dynamo.

Introducing Dynamo

Currently available as an add-on for several Autodesk products, Dynamo offers a visual programming interface that lets you automate repetitive tasks with minimal coding. Rather than typing code, you drag and drop components into a graphical environment and process your routines in the same environment.

The examples in this article will be based on a Civil 3D environment, but most of the concepts also apply to Revit and other products. In 2015 Autodesk launched a companion product, Dynamo Studio, to help developers, but recently announced plans to discontinue it, as Dynamo’s capabilities were extended to Civil 3D, Revit, and other products.

For more experienced programmers, Dynamo can also operate as a standalone product, with its own runtime, and can access other products through connectors. Dynamo core technology is available for free download through Dynamo Sandbox.

Installing and starting Dynamo

If you’re new to Dynamo, the first step is to make sure it’s installed in your CAD environment. For Civil 3D 2021 and later, it is included in the main product installer as an optional subcomponent. For Civil 3D 2020 you need to do a separate download and installation from your Autodesk Account. Once installed, Dynamo icons appear in the Manage tab.

When you click on the Dynamo you will see an initial screen with options to create a new Dynamo file, open recent files, and perform various other tasks.

Click on New to create a new file. You’ll then see Dynamo’s main interface, with menu choices at the top, a Library pane along the left, and a grid taking up the majority of the window.

Create something in Dynamo

To see how Dynamo works, let’s look at a simple example: how to draw a line using Dynamo.

1. In the Library pane, you will see a series of categories. Click and expand the Geometry category to display additional choices.

2. Click and expand the Curves and Double categories in the same way. You will see a series of nodes, which are Dynamo’s main building blocks. They represent the objects and commands you will use to create a Dynamo routine or script. (In the Dynamo geometry tree, a line is considered a type of curve.)

3. Hover your cursor over some nodes to see a description of each node, then click ByStartPointendPoint to select it. This places a node in the workspace.

4. Hover over the different elements of the node area and you will see what type of input is required. For example, the starting point will require an entry point. On the right side of the box is the output of the node – in this case, a line.

5. To find different ways to enter point data, type “point” in the search box.

6. From the list of choices for point data entry, select ByCoordinates. This places another node in the workspace.

7. Drag the Point.ByCoordinates node to the left of your line node. Dynamo workflows are generally best organized to progress from left to right.

8. Click on the Indicate box inside the Point.ByCoordinates node and connect it to starting point box in the row node. You have now created a wire connecting two nodes. The output of the box on the left provides the input for the next box.

Introducing Dynamo

9. Create an add-in Point.ByCoordinates node for the endpoint and connect it to the period box in the row node.

ten. Create additional nodes and connect them with wires to provide the necessary input for the start and end points of the line. Use a basic numeric node to enter points and change some of the values ​​so that the start point and the end point are different. When you’re done, your workspace should look like this:

Introducing Dynamo

11. Right click on your input nodes and rename them to more logical names. (This step is optional.)

12. Type various numbers into the input nodes and notice how the row changes in the grid as you change the input values.

13. Of Case menu, click Save to save your Dynamo script under a name of your choice.

Bring an object into your drawing

We’ve drawn a line, but it’s not yet part of an AutoCAD drawing. To do this, we need to add a few more nodes to our workflow.

1. In the lower left corner of the Dynamo window, click the icon Automatique drop down and change the execution mode to Manual. This lets you determine when to run the script.

2. In the Library pane search box, type “object.by” to find ways to create objects. Click on Object.ByGeometry to add this node to your workspace and move it to the right of the other nodes.

3. Connect the line node to the geometry box of the Object.ByGeometry node, using the same techniques you used earlier.

4. Add nodes to identify the current document and model space using the Document. Current and Document.ModelSpaceDocument.ModelSpace knots.

5. Add one Rope node to identify the layer and type “0” to place the line on layer 0. (You can change it to another layer of your choice.) The string node is used to enter text instead of numbers.

6. Connect the nodes as shown below.

7. Click on Course in the lower left corner of the Dynamo window to run your script.

8. Minimize the Dynamo window to view the AutoCAD drawing. You should see a line drawn in model space.

Now what?

You may be thinking, “So what? I just created a line, which I could have done much faster in AutoCAD or Civil 3D. This example was simply intended to show how to perform a simple task in Dynamo; the true power of Dynamo is harnessed when you automate tedious or repetitive tasks and reuse scripts multiple times, which can save you a ton of time.

Once you know how to create and connect nodes, you can expand your repertoire to create more complex objects, as well as modify objects already in a drawing. You can also extract information from a drawing and export it to spreadsheets or other locations, allowing you to create reports and share data with colleagues.

To run previously recorded Dynamo scripts, check out the Dynamo Player, accessible via the icon right next to the Dynamo icon you clicked to launch Dynamo. The player lets you load and run scripts, as well as share your scripts with others.

Also check out the references listed in the initial screen you saw when you first launched Dynamo. Autodesk provides a helpful Getting Started document, as well as other references and sample scripts. Forums such as the one found at dynamobim.com can be particularly helpful. Since Dynamo is an open source platform and is constantly under development, you may encounter situations where a technique works fine in the current version of your CAD product, but not in an older version, or vice versa. You may even experience bugs or weird behavior. Forums are often visited by helpful people who have encountered similar situations and can help solve your problem.

In a future article, we’ll explore some more complex tasks that can be accomplished using Dynamo. If you have specific ideas, do not hesitate to send me an e-mail.