Dynamo in Civil 3D Introduction - Unlocking The Mystery of Scripting
Dynamo in Civil 3D Introduction - Unlocking The Mystery of Scripting
Andrew Milford
Autodesk
Learning Objectives
• Understand the basic uses of AutoCAD and Civil3D dynamo nodes
• Learn how to import / export data from Excel using dynamo
• Learn how to leverage basic nodes in automating your design changes
• Create reusable graphs to accelerate your design process
Description
Delivering an infrastructure project is becoming more time consuming as we are now required to
provide not only detailed models, but also more information. Modifying and reviewing designs
and making all dependent geometry update to a new location with a click of a button is a game
changer. In this class, you will learn the basics of AutoCAD and Civil 3D Dynamo nodes and
how you can leverage Dynamo graphs in automating tedious tasks.
Speaker(s)
Jowenn Lua is a Road Design Digital Engineering Systems Specialist for
Arcadis. He holds a B.S. Civil Engineering degree from De La Salle University
and MBA degree from Ateneo De Manila University. He is a member of the
2016 Autodesk Gunslinger in Australia and participated in the ‘2018 Civil
Infrastructure Inside the Factory’ held in Potsdam, Germany. In February
2019, he became a member of Autodesk Expert Elite. He has over 16 years
industry experience in design and construction. He was previously working as
the Lead Civil 3D designer in the Sydney Metro and is one of the key persons
who developed the project’s Civil 3D system, template, plan production and tool palette
pushout. He is highly skilled in Civil 3D & subassembly composer and provides mentoring and
solutions to the team.
Page 1
Andrew Milford is a Senior Implementation Consultant for Autodesk
and is responsible for post-sales technical and business consulting to
ensure customers achieve successful adoption of Autodesk's
Infrastructure Solutions across the Asia/Pacific region. Prior to joining
Autodesk, Andrew gained over 25 years of design experience in the
civil infrastructure industry, working as a geometric road designer for
large consulting companies such as SKM/Jacobs, Arcadis, and
AECOM. Andrew’s experience extends from designing large highways,
tunnels, and interchanges down to smaller subdivision work using a variety of different design
and drafting software packages. He is an AutoCAD Civil 3D Certified Professional and loves
diving deep into AutoCAD Civil 3D software to develop and automate processes through scripts,
AutoLISP , .NET API C# and VB and Python.
Page 2
Introduction
This class will demonstrate real world scenarios where you can leverage the use of Dynamo
graphs in your design workflow. You will gain some basic knowledge in using Dynamo and will
equip you with tips and tricks to help you learn faster.
Page 3
Why use D4C3D?
• Remove repetitive tasks & create automation
• Improve efficiency & collaboration
• Re-use graph from project to project
Where do I start?
• D4C3D start-up interface will look like this. You can learn from reference and start a new
file or open an existing file.
Page 4
D4C3D Interface
• Opening a new file will give you a blank Dynamo interface.
• You can expand the Library to get a node or type in the search tab to look for a node.
Page 5
Basic uses of AutoCAD and Civil 3D Dynamo nodes
Understanding the basic uses of D4C3D nodes are very important and will require a lot of
reading, practice and testing of sample cases. Sample case files are available, and it is located
in the following link:
C:\ProgramData\Autodesk\C3D 2020\Dynamo\Samples
C:\ProgramData\Autodesk\C3D 2020\Dynamo\API Samples
These sample cases were explained in the Autodesk knowledge network. It is highly
recommended to open them and check them out. <D4C3D Case Link>
It is also important to be open-minded when learning D4C3D as there are so many ways to
achieve the same outcome. You may encounter a better workflow as time goes by as it is part of
the learning journey. What is important is that you try to test D4C3D and see how you can
automate some of the repetitive or complex tasks that you normally do.
D4C3D will give you built-in nodes that can do specific functions and they are categorized in the
Library. The first two in the Library are AutoCAD and Civil 3D Nodes and the rest is part of the
Dynamo core which is common to other software that uses Dynamo like Revit.
Page 6
Node default value & result preview
• Hover your mouse to the input port to display tool tip for variable type and default value
• Hover your mouse to AUTO will allow you to pin and unpin the result preview
Types of nodes
In this class, we will focus more in highlighting AutoCAD and Civil 3D nodes, but we will use
some of the Dynamo core nodes that will help us achieve a certain task.
Code Blocks
Code blocks are text interface that can be used as numbers, strings, formula, list, variable and
other available data types. Code block allows design script code to be authored directly. Double
click your mouse in the workspace / canvas to create a code block.
Page 7
Code block as Boolean expression
• A == B equality
• A != B inequality
• A < B less than
• A <= B less than or equal to
• A > B greater than
• A >= B greater than or equal to
• && logical AND (true only if all the arguments are true)
• || logical OR (true if at least one argument is true)
Page 8
Watch Node
It is essential to see the output or result of your design graphs. Using Watch Nodes will allow
you to visualize design graph progress and result.
Number Ranges
In Dynamo, you will encounter a lot of cases where you want to create different types of
continuous or ranges of numbers. Understanding the power of design script inside a code block
will come very handy in your design graph creation.
Page 9
Sample:
• Start..End; a range of numbers
• Start..End..Step; a range of numbers with step
• Start..End..~Step; a range with an approximate step
• Start..End..#Items; a range of a given number of items
• Start..#Items..Step; a sequence with a number of items and a step
List
In programming world, list is built on top of array. In Dynamo, it is a collection of elements or
items in order. The first item is always an index “0” (Zero). You can have list of a single item, list
of multiple items, list of lists, or have a list of list of list. You can mix any list and can be useful if
you know how to get them by their indexes.
Sample:
• List[a]; returns the item in the list at index “a”
• List[-a]; return the item starting from end of the list till “a”, List[-1] gives end of list
• List[a][b]; returns the item in sublist at index “b” of list “a”, If [-a][b] will start from end
• List[a..b]; returns the item in the list between the indexes “a” to “b”
• List[[a,b,c]]; returns the item in the list respectively at location “a”, “b” and “c”
• [a,b,c]; declare a list in code blocks
Page 10
AutoCAD Nodes & Civil 3D Nodes
These are nodes specifically created for automating AutoCAD and Civil 3D
tasks through Dynamo. For D4C3D release 2020, it has Documents, Objects,
Selection under the AutoCAD library and CivilObjects, Selection under the
Civil 3D library.
Installing release 2020.1 will give you additional dynamo nodes. To name a
few, it now includes PropertySet, CogoPoints, Surfaces, Profiles nodes.
One of the most important nodes in the AutoCAD library that will be used
often is the “Document.Current” node. This is needed to link the current opened drawing to the
current opened dynamo file.
Page 11
ACAD object transfer
For object, the two most important nodes to remember are Object.Geometry and
Object.ByGeometry.
The Object.Geometry allows you to convert an object from CAD to Dynamo geometry.
Sample:
AutoCAD > Objects > Object > Geometry
Sample:
AutoCAD > Objects > Object > ByGeometry
Page 12
ACAD object selection
One of the basic object selections to use is ‘selecting by object’. Although you can only select
one object at a time, it has the ability to pick from screen which object to use. Alternatively, you
can also select object by its type or by its layer.
Sample:
AutoCAD > Selection > Select Object
AutoCAD > Selection > Objects Types
AutoCAD > Selection > All Objects of Type
AutoCAD > Selection > All Objects on Layer
Sample:
AutoCAD > Selection > ObjectsByProperty
AutoCAD > Selection > Value Operators
Page 13
Import / Export data from Excel using Dynamo
Data manipulation is one of the strengths of using Dynamo. The ability to import and export to
excel is very important especially when you want to import raw data and build geometry then do
some calculations and export it back with a user defined report format.
Page 14
Export data to Excel (Dynamo to Excel)
1. Browse the file using “File Path” node
2. Connect the “File Path” to “Excel.ReadFromFile” node to get the actual file
3. Assign a sheet name to write data to
4. Assign number for start Row and Column
5. Connect the lists to data to get the information needed
6. Assign Boolean decision True / False or accept default value
Page 15
Import data from CSV (CSV to Dynamo)
Option 1
1. Browse the file using “File Path” node
2. Connect the “File Path” to “File.FromPath" node to get the actual file
3. Connect the file to “FileSystem.ReadText” node
4. Manipulate data by “String.Split” and “String.ToNumber” from String nodes
5. Process data by List and Geometry nodes
Option 2
1. Browse the file using “File Path” node
2. Connect the File Path to “Data.ImportCSV” node
3. Assign Boolean decision True / False or accept default value
Page 16
From Option 1 graph
Page 17
Leverage basic nodes in automating your design
Out of the box (OOTB) nodes are very powerful and can usually be
found in every graph. The most common basic nodes are found in the
Geometry, List and Math libraries.
The following example demonstrates how to use an Excel file to drive data creation within Civil
3D. Conversely, Excel files can be used to extract data from the design model for reporting
purposes.
1. Sketch an overview workflow on how you will automate the process. The is process can be
done on a computer or even mapped out on a whiteboard.
Page 18
2. Block References in Dynamo can be either 2D, 3D or Multi-View blocks. To prepare a
Multi-View block, a 2D and 3D block are required.
For more information about Multi-View Blocks refer to the link below:
https://knowledge.autodesk.com/support/civil-3d/learn-
explore/caas/CloudHelp/cloudhelp/2017/ENU/Civil3D-UserGuide/files/GUID-8EC3AE29-
516A-445F-A134-D939B30C2E41-htm.html
This example uses a simple 3D block which has been created in Inventor and exported
as a DWG file.
To make full use of these blocks in later exercise, The light pole has been modelled as
an ‘Assembly’, which is built up of three ‘parts’, including the light head, pole and footing.
It is the footing that will be used as part of a clash detection and space proofing exercise.
Page 19
Page 20
3. An Excel file is setup to with some parameters in which to create the data that Dynamo
will use to lace the Civil 3D objects. Columns include:
• Sign Type – This is the name of the AutoCAD block reference
• Control Line – The alignment against which the block is to be placed
• Chainage – the chainage (or station) where the object is to be placed
• Offset – Distance from the alignment
• Side – use LHS or RHS to determine which side of the alignment to place the
object
Page 21
4. Setup the Dynamo graph that uses the basic nodes for AutoCAD and Civil 3D.
Page 22
Exercise 2 - Creating Corridor Solids
• AU2019_02_Corridor Solids.dyn
In this exercise, the aim is to extract information from the Civil 3D model to create a Dynamo
version of the corridor solid. This Dynamo solid will be used in the next exercise as part of a
space proofing and clash detection exercise.
1. Before beginning the Dynamo graph, it is required to setup the Civil 3D drawing to
prepare the model for export.
This involves setting up consistent point, link and shape codes that will be used across
multiple models.
Page 23
2. Like all examples in this document, start the Dynamo graph with a reference to the
current document
Page 24
5. Create a Dynamo solid from the baseline footing shape.
Create a simple Dynamo polygon object from each list of points. Polygons are useful in
this situation as they are a closed-object by default.
It is also viable to use a PolyCurve, however an additional node is required to close the
PolyCurve before lofting.
Page 25
Create reusable graphs to accelerate your design process
Exercise 3 - Space Proofing and Clash Detection
• AU2019_03_Space Proofing.dyn
In this exercise, the Dynamo Corridor solid information produced in Exercise 2 will be used to
clash against the road furniture items created in Exercise 1
Almost half of this graph is copied from the previous exercise, where the creation of footing
solids from a barrier corridor was undertaken.
The resulting output will be a series of geometric spheres at the clash locations (in Dynamo and
Civil 3D)
1. The first group in this graph will import the same Excel data that was used in Exercise 1
(Object placement). The aim of this import is to get a list of all the blocks that have been
placed in the Civil 3D model. This is achieved with the ImportExcel node and the header
is remove with the List.Deconstruct.Finally, the unique items from the list are extracted
using a List.UniqueItems node
Page 26
2. The bottom half of the graph uses the current document to extract the corridor and then
get the corridor baseline shapes from the barrier footing.
Dynamo solids are created using a Solid.ByLoft, which is identical to the process used in
Exercise 2
Page 27
Working with large geometry (i.e. far from 0,0) can produce warnings in Dynamo, similar to the
image below-left. The node highlights in yellow and a message stating …”Geometry Working
Range” appears. In a bubble above the node. This is due to the data being far from the origin
and does not affect the way Dynamo calculated the information. This will, however, affect the
display of geometry, which may become faceted and look rather ‘odd’.
There is an option to change the Geometry Working Range through the Settings > Geometry
Scaling option. By default, Dynamo uses the ‘Medium’ setting
It is advised not to change this setting, and to leave it at ‘Medium’
Changing the range to a setting of ‘Large’ or ‘Extra large’ will result in Dynamo recalculating the
geometry differently and will produce some unexpected results in geometry.
This is the reason why the node contains the Geometry.Translate set of nodes, to temporarily
translate the geometry close to origin to produce a higher-quality better visual output,
Page 28
3. Extract the Block Reference from AutoCAD
To provide a set of objects for the footing to clash against, it is necessary to extract the
already-inserted block information from the Civil 3D drawing.
To do this, extract All Objects of Type (in this case, a Block Reference), and test the
block name against all the blocks in Excel file.
This will return a True/False list, which will then create a filtered list of items and their
corresponding CoordinateSystem/setout location.
4. With the block objects identified for clash, extract the information from the block. This is
achieved with the Block.Objects node. This will extract the individual objects of a block.
In this case, a list of solids which is the converted to Dynamo geometry using the
Object.ByGeometry node.
As the clash detection will take place underground, there is no need to consider
elements above the surface. In this case, each object has a footing, which is the lowest
item in the block element list.
To optimise the performance of the graph and remove unwanted clash checks, extract
only the block item at the lowest elevation (or ‘Z’ value). This is done by:
• Get all Dynamo geometry solids (Object.Geometry)
• Get the centroid of all Dynamo solids (Solid.Centroid)
• Get the Z point of each centroid (Point.Z)
• Sort the items in each sublist by the centroid ‘Z’ value (List.SortByKey)
• With each list sorted by ‘Z’, take only the first item in each sublist
(List.GetItemAtIndex)
Page 29
5. Using the Geometry.Intersect, clash the two groups of items against each other.
Ensure to use ‘Cross Product’ lacing to ensure every item in each list is checked against
the other.
Once the clash is complete, create Dynamo spheres to visualise the clash points
Optional: Recreate the clash spheres in Civil 3D
Page 30
Exercise 4 - Sight Line Analysis
• AU2019_04_Sight Lines from Excel.dyn
In this final exercise, we will explore the Civil 3D surface nodes to create a series of sight-line
analyses, all based on values provided through an Excel spreadsheet. Finally, the results of
these analyses will be displayed in different colours in Dynamo and AutoCAD.
This example extends the current Civil 3D Sight Analysis in that users are able to plot multiple
analyses within a single graph.
1. The first step is to setup and import an Excel file, containing information such as the
following
• Alignment
• Offset
• Side
• Eye height
• Object height
• Sight Distance
• Check Interval
These values will provide all the information required to create a successful sight line
analysis. Each row in Excel equates to one sight line analysis.
Page 31
Figure 7: Extract the Final surface from Civil 3D
Once the points have been placed at the horizontal locations, the surface is used to
extract the relevant elevation transforms applied to each eye/target point.
Page 32
5. Create sight lines and surface intersection points
At each sight line a Coordinate System is located the eye point, with the coordinate
systems’ ‘Y’ vector pointing towards the target.
6. The Surface.IntersectionPoints is used to project a vector on the coordinate system. If
no intersection is detected, a null value is returned. In this instance, the null value is
replaced by an extremely large value
Page 33
Bonus Information
Generating geometry from Dynamo and exporting it back to Civil 3D is very useful. It is also
important to know how to leverage the property sets in Civil 3D. It is highly recommended for
you to check our AU 2018 class: CI225967 – Using Automation in Civil 3D for Construction
Documentation and Exports. In pages 43 onwards you can see detailed guidance on how to
create property sets and how to use ‘STYLEMANAGE’ via command line.
Another strength of using D4C3D is the ability to automate the information in your property set
and to add rich meta data to your civil objects.
Page 34
2. Create an overview workflow on how you will do the process.
3. Prepare a property set data for line and polyline via ‘STYLEMANAGE’. (Format, List, Set)
Page 35
• Current Limitations using Object.UpdateProperty in Dynamo
Page 36
4. Setup Dynamo graph that uses the nodes from Core, AutoCAD and Civil 3D.
5. Sample outcome – All dynamic to geometry and will update everything below.
Page 37
Bonus Class Dynamo Files
As you use Dynamo on a regular basis, you will see pattern of some basic nodes that you keep
on using. It is important to remember that creating small reusable graph is the key to
successfully implementing a good design workflow. If you focus on building smaller and
manageable graph that can easily be understood, properly documented and being shared to the
team, then it will help boost the productivity of the team simply because they can always grab
smaller graph and create a more complex custom made graph.
Sample:
You can create a helper template that have all the basic nodes that you will use again and
again. You can also create a python collection that you can refer anytime without closing the
current dynamo file opened.
Sample:
Page 38
Reference
Page 39
Appendix 1 – Shortcut Key
Shortcut Key Description Image
Ctrl+B Swap background code blocks
and 3d drawings (vice versa)
Page 40
Appendix 2 – AutoCAD 2020 vs 2020.1
Page 41
Appendix 3 – Civil 3D 2020 vs 2020.1
Page 42
Acknowledgement
Learning Dynamo for Civil 3D requires lots of research, reading and testing. I would like to say
thanks to Brett Burling (Arcadis) for support in API, Dynamo and D4C3D custom tool
development. Also, we have a very strong support from Autodesk and would like to say special
thank you to Jacob Small and Frank Huang for their technical advices.
Page 43