Dynamo Primer
Dynamo Primer
html
INTRODUCTION
From its origins as an add-on for Building Information Modeling in Revit, Dynamo has matured to become many things. Above all else it is a platform, enabling
designers to explore visual programming, solve problems, and make their own tools. Let's start our journey with Dynamo by set ting some context - what is it and how
do I approach using it?
About
1. Introduction
o 1.1. What is Visual Programming?
o 1.2. What is Dynamo?
o 1.3. Dynamo in Action
2. Hello Dynamo!
o 2.1. Installing and Launching Dynamo
o 2.2. The User Interface
o 2.3. The Workspace
o 2.4. Getting Started
3. The Anatomy of a Visual Program
o 3.1. Nodes
o 3.2. Wires
o 3.3. Library
o 3.4. Managing Your Program
4. The Building Blocks of Programs
o 4.1. Data
o 4.2. Math
o 4.3. Logic
o 4.4. Strings
o 4.5. Color
5. Geometry for Computational Design
o 5.1. Geometry Overview
o 5.2. Vectors
o 5.3. Points
o 5.4. Curves
o 5.5. Surfaces
o 5.6. Solids
o 5.7. Meshes
o 5.8. Importing Geometry
6. Designing with Lists
o 6.1. What's a List
o 6.2. Working with Lists
o 6.3. Lists of Lists
o 6.4. n-Dimensional Lists
7. Code Blocks and DesignScript
o 7.1. What's a Code Block
o 7.2. DesignScript Syntax
o 7.3. Shorthand
o 7.4. Functions
8. Dynamo for Revit
o 8.1. The Revit Connection
o 8.2. Selecting
o 8.3. Editing
o 8.4. Creating
o 8.5. Customizing
o 8.6. Documenting
9. Dictionaries in Dynamo
o 9.1. What is a Dictionary
o 9.2. Node Uses
o 9.3. Code Block Uses
o 9.4. Use-Cases
10. Custom Nodes
o 10.1. Custom Node Introduction
o 10.2. Creating a Custom Node
o 10.3. Publishing to Your Library
o 10.4. Python Nodes
o 10.5. Python and Revit
o 10.6. Python Templates in Dynamo 2.0
11. Packages
o 11.1. Package Introduction
o 11.2. Package Case Study - Mesh Toolkit
o 11.3. Developing a Package
o 11.4. Publishing a Package
o 11.5. Zero-Touch Importing
12. Geometry with DesignScript
o 12.1. DesignScript Geometry Basics
o 12.2. Geometric Primitives
o 12.3. Vector Math
o 12.4. Curves: Interpolated and Control Points
o 12.5. Translation, Rotation, and Other Transformations
o 12.6. Surfaces: Interpolated, Control Points, Loft, Revolve
o 12.7. Geometric Parameterization
o 12.8. Intersection and Trim
o 12.9. Geometric Booleans
o 12.10. Python Point Generators
13. Best Practices
o 13.1. Graph Strategies
o 13.2. Scripting Strategies
o 13.3. Scripting Reference
14. Appendix
o 14.1. Resources
o 14.2. Index of Nodes
o 14.3. Useful Packages
o 14.4. Example Files
Algorithms in Hand
While offering some powerful opportunities, the term Algorithm can carry some misconceptions with it. Algorithms can generate unexpected, wild, or cool things, but
they are not magic. In fact, they are pretty plain, in and of themselves. Let's use a tangible example like an origami crane. We start with a square piece of paper
(input), follow a series of folding steps (processing actions), and result in a crane (output).
So where is the Algorithm? It is the abstract set of steps, which we can represent in a couple of ways - either textually or graphically.
Textual Instructions:
1. Start with a square piece of paper, colored side up. Fold in half and open. Then fold in half the other way.
2. Turn the paper over to the white side. Fold the paper in half, crease well and open, and then fold again in the other directi on.
3. Using the creases you have made, Bring the top 3 corners of the model down to the bottom corner. Flatten model.
4. Fold top triangular flaps into the center and unfold.
5. Fold top of model downwards, crease well and unfold.
6. Open the uppermost flap of the model, bringing it upwards and pressing the sides of the model inwards at the same time. Flatten down, creasing well.
7. Turn model over and repeat Steps 4-6 on the other side.
8. Fold top flaps into the center.
9. Repeat on other side.
10. Fold both ‘legs’ of model up, crease very well, then unfold.
11. Inside Reverse Fold the “legs” along the creases you just made.
12. Inside Reverse Fold one side to make a head, then fold down the wings.
13. You now have a crane.
Graphical Instructions:
Programming Defined
Using either of these sets of instructions should result in a crane, and if you followed along yourself, you've applied an al gorithm. The only difference is the way in
which we read the formalization of that set of instructions and that leads us to Programming. Programming, frequently shortened from Computer Programming, is
the act of formalizing the processing of a series of actions into an executable program. If we turned the above instructions for a creating crane into a format our
computer can read and execute, we are Programming.
The key to and first hurdle we will find in Programming, is that we have to rely on some form of abstraction to communicate e ffectively with our computer. That takes
the form of any number of Programming Languages, such as JavaScript, Python, or C. If we can write out a repeatable set of instructions, like for the origami crane,
we only need to translate it for the computer. We are on our way to having the computer be able to make a crane or even a mul titude of different cranes where each
one varies slightly. This is the power of Programming - the computer will repeatedly execute whatever task, or set of tasks, we assign to it, without delay and without
human error.
Textual Program:
myPoint = Point.ByCoordinates(0.0,0.0,0.0);
x = 5.6;
y = 11.5;
attractorPoint = Point.ByCoordinates(x,y,0.0);
dist = myPoint.DistanceTo(attractorPoint);
myCircle = Circle.ByCenterPointRadius(myPoint,dist);
The results of our algorithm:
The visual characteristic to programming in such a way lowers the barrier to entry and frequently speaks to designers. Dynamo fal ls in the Visual Programming
paradigm, but as we will see later, we can still use textual programming in the application as well.
What is Dynamo?
Dynamo is, quite literally, what you make it. Working with Dynamo may include using the application, either in connection wit h other Autodesk software or not,
engaging a Visual Programming process, or participating in a broad community of users and contributors.
The Application
Dynamo, the application, is a software that can be downloaded and run in either stand -alone "Sandbox" mode or as a plug-in for other software like Revit or Maya. It is described as:
A visual programming tool that aims to be accessible to both non-programmers and programmers alike. It gives users the ability to visually script behavior, define custom pieces of logic, and
script using various textual programming languages.
The Process
Once we've installed the application, Dynamo will enable us to work within a Visual Programming process wherein we connect elements together to define the relat ionships and the sequences
of actions that compose custom algorithms. We can use our algorithms for a wide array of applications - from processing data to generating geometry - all in real time and without writing a lick
of code.
Add elements, connect, and we are off and running with creating Visual Programs.
The Community
Dynamo wouldn't be what it is without a strong group of avid users and active contributors. Engage the community by following the Blog, adding your work to the Gallery, or discussing Dyn amo
in the Forum.
The
Platform
Dynamo is envisioned as a visual programming tool for designers, allowing us to make tools that make use of external libraries or any Autodesk product that has an API. With Dynamo Studio
we can develop programs in a "Sandbox" style application - but the Dynamo ecosystem continues to grow.
The source code for the project is open-source, enabling us to extend its functionality to our hearts content. Check out the project on GitHub and browse the Works in Progress of users
customizing Dynamo.
Browse, Fork, and start extending Dynamo for your needs
DYNAMO IN ACTION
From using Visual Programming for project workflows to developing customized tools, Dynamo is an integral aspect to a wide variety of exciting applications.
HELLO DYNAMO!
At its core, Dynamo is a platform for Visual Programming - it is a flexible and extensible design tool. Because it can operate as a stand-alone application or as an add-on to other design
software, we can use it to develop a wide range of creative workflows. Let's install Dynamo and get started by reviewing the key features of the interface.
The User Interface (UI) for Dynamo is organized into five main regions, the largest of which is the workspace where we compose our vis ual programs.
1. Menus
2. Toolbar
3. Library
4. Workspace
5. Execution Bar
Let's dive deeper into the UI and explore the functionality of each region.
Menus
The Dropdown Menus are a great place to find some of the basic functionality of the Dynamo application. Like most Windows sof tware, actions related to managing files and operations for
selection and content editing are found in the first two menus. The remaining menus are more specific to Dynamo.
1. File
2. Edit
3. View
4. Packages
5. Settings
6. Help
7. Notifications
Toolbar
Dynamo's Toolbar contains a series of buttons for quick access to working with files as well as Undo [Ctrl + Z] and Redo [Ctr l + Y] commands. On the far right is another button that will export
a snapshot of the workspace, which is extremely useful for documentation and sharing.
Browsing
By default, the Library will contain eight categories of Nodes. Core and Geometry are great menus to begin exploring as they contain the largest quantity of Nodes. Browsing through these
categories is the fastest way to understand the hierarchy of what we can add to our Workspace and the best way to discover ne w Nodes you haven't used before.
We will focus on the default collection of Nodes now, but note that we will e xtend this Library with Custom Nodes, additional libraries, and the Package Manager later.
1. Dictionary
2. Display
3. Geometry
4. ImportExport
5. Input
6. List
7. Matches
8. Revit
9. Script
10. String
11. Add-ons
Browse the Library by clicking through the menus. Click the Geometry > Curves > Circle. Note the new portion of the menu that is revealed and specifically the Create and Query Labels.
1. Library
2. Category
3. Subcategory: Create/Actions/Query
4. Node
5. Node Description and properties - this appears when hovering over the node icon.
From the same Circle menu, hover your mouse over ByCenterPointRadius. The window reveals more detailed information about the Node beyond its name and icon. This offers us a quick
way to understand what the Node does, what it will require for inputs, and what it will give as an output.
Searching
If you know with relative specificity which Node you want to add to your Workspace, the Search field is your best friend. When you are not editing settings or specifying values in the Workspace, the
cursor is always present in this field. If you start typing, the Dynamo Library will reveal a selected best fit match (with b readcrumbs for where it can be found in the Node categories) and a list of
alternate matches to the search. When you hit Enter, or click on the item in the truncated browser, the highlighted Node is added to the center of the Workspace.
1. Search Field
2. Best Fit Result / Selected
3. Alternate Matches
Settings
From geometric to user settings, these options can be found in the Settings menu. Here you can opt in or out for sharing your user data to improve Dynamo as well as define the application's
decimal point precision and geometry render quality.
1. Enabling Reporting - Options for sharing user data to improve Dynamo.
2. Show Run Preview - Preview the execution state of your graph. Nodes scheduled for execution will be highlighted in your graph.
3. Number Format Options - Change the document settings for decimals.
4. Render Precision - Raise or lower the document render quality.
5. Geometry Scaling - Select range of geometry you are working on.
6. Isolate Selected Geometry - Isolated background geometry based on your node selection.
7. Show/Hide Geometry Edges - Toggle 3D geometry edges.
8. Show/Hide Preview Bubbles - Toggle data preview bubbles below nodes.
9. Manage Node and Package Paths - Manage file paths to make nodes and packages show up in the Library.
10. Enabling Experimental Features - Use beta features new in Dynamo.
Help
If you're stuck, check out the Help Menu. Here you can find the sample files that come with your installation as well as access one of the Dynamo reference websites through your internet
browser. If you need to, check the version of Dynamo installed and whether it is up to date through the About option.
1. Getting Started - A brief introduction to using Dynamo.
2. Samples - Reference example files.
3. Open Dynamo Dictionary - Resource with documentation on all nodes.
4. Report A Bug - Open an Issue on GitHub.
5. Go To Project Website - View the Dynamo Project on GitHub.
6. Go To Project Wiki - Visit the wiki for learning about development using the Dynamo API, supporting libraries and tools.
7. Display Start Page - Return to the Dynamo start page when within a document.
8. About - Dynamo Version data.
The Workspace
The Dynamo Workspace is where we develop our visual programs, but it's also where we preview any resulting geometry. Whether we are working in a H ome Workspace or a Custom Node,
we can navigate with our mouse or the buttons at top right. Toggling between modes at bottom right switches which preview we navigate.
Note: Nodes and geometry have a draw order so you may have objects rendered on top of each other. This can be confusing when adding multiple nodes in sequence as they may be
rendered in the same position in the Workspace.
1. Tabs
2. Zoom/Pan Buttons
3. Preview Mode
4. Double Clicking on the Workspace
Tabs
The active Workspace tab allows you to navigate and edit your program. When you open a new file, by default you are opening a new Home Workspace. You may also open a new Custom
Node Workspace from the File Menu or by the New Node by Selection right click option when Nodes are selected (more on this functionality later).
Note: You may have only one Home Workspace open at a time; however, you may have multiple Custom Node Workspac es open in additional tabs.
The 3D Preview Navigation mode also gives us the ability for Direct Manipulation of points, exemplified in Getting Started.
Zoom to Recenter
We can easily pan, zoom and rotate freely around models in 3D Preview Navigation mode. However, to zoom specifically on an ob ject created by a geometry node, we can use the Zoom All
icon with a single node selected.
1. Select the node corresponding to the geometry that will center the view.
2. Switch to the 3D Preview Navigation.
1. Click on the Zoom All icon in the top right.
2. The selected geometry will be centered inside the view.
Hello Mouse!
Based on which Preview mode is active, your mouse buttons will act differently. In general, the left mouse click selects and spec ifies inputs, the right mouse click gives access to options, and
the middle mouse click allows you to navigate the Workspace. The right mouse click will present us with options based on the context of where we are clicking.
1. Right Click on the Workspace.
2. Right Click on a Node.
3. Right Click on a Note.
In-Canvas Search
Using the "In-Canvas Search" will add some serious speed to your Dynamo work-flow by providing you access to node descriptions and tool-tips without taking you away from your place on
the graph! By just right-clicking, you can access all the useful functionality of the "Library Search" from wherever you happen to be working on the canvas.
1. Right click anywhere on the canvas to bring up the search feature. While the search bar is empty, the drop -down will be a preview menu.
2. As you type into the search bar, the drop-down menu will continuously update to show the most relevant search results.
3. Hover over the search results to bring up their corresponding descriptions and tool -tips.
3. The nodes will be automatically re-distributed and aligned, cleaning up any staggered or overlapping nodes and aligning them with neighboring nodes.
GETTING STARTED
Now that we have familiarized ourselves with the interface layout and navigating the Workspace, our next step is to understand the typical workflow for developing a graph in Dynamo. Let's get
started by creating a dynamically sized circle and then create an array of circles with varying radii.
A point that defines a distance-based relationship is commonly referred to as an "Attractor." Here the distance to our Attractor Point will be used to specif y how big our circle should be.
Let's add the Circle.ByPointRadius Node to the Workspace by clicking on it in the Library - this should add the Node to the center of the Workspace.
1. The Circle.ByPointandRadius Node in the Library
2. Clicking the Node in the Library adds it to the Workspace
We also will need Point.ByCoordinates, Number Input, and Number Slider Nodes.
Adding Detail
If our program is working, we should see a circle in the 3D Preview that is passing through our Attractor Point. This is grea t, but we may want to add more detail or more controls. Let's adjust the
input to the circle Node so that we can calibrate the influence on the radius. Add another Number Slider to the Workspace, then double click on a blank area of the Workspace to add a Code Block
Node. Edit the field in the Code Block, specifying X/Y.
1. Code Block
2. DistanceTo and Number Slider to Code Block
3. Code Block to Circle.ByCenterPointRadius
Adding complexity
Starting simple and building complexity is an effective way to incrementally develop our program. Once it is workin g for one circle, let's apply the power of the program to more than one circle.
Instead of one center point, if we use a grid of points and accommodate the change in the resulting data structure, our progr am will now create many circles - each with a unique radius value defined
by the calibrated distance to the Attractor Point.
1. Add a Number Sequence Node and replace the inputs of Point.ByCoordinates - Right Click Point.ByCoordinates and select Lacing > Cross Reference
2. Add a Flatten Node after Point.ByCoordinates. To flatten a list completely, leave the amt input at the default of -1
3. The 3D Preview will update with a grid of circles
Nodes
In Dynamo, Nodes are the objects you connect to form a Visual Program. Each Node performs an operation - sometimes that may be as simple as storing a number
or it may be a more complex action such as creating or querying geometry.
Anatomy of a Node
Most Nodes in Dynamo are composed of five parts. While there are exceptions, such as Input Nodes, the anatomy of each Node ca n be described as follows:
Tip: Hover over a Port to see a tooltip containing the data type expected.
1. Port Label
2. Tool Tip
3. Data Type
4. Default Value
States
Dynamo gives an indication of the state of the execution of your Visual Program by rendering Nodes with different color schem es based on each Node's status. Furthermore, hovering or right-clicking
over the Name or Ports presents additional information and options.
1. Active - Nodes with a Dark Grey Name background are well-connected and have all of their inputs successfully connected
2. Inactive - Grey Nodes are inactive and need to be connected with Wires to be part of the Program Flow in the active Wo rkspace
3. Error State - Red indicates that the Node is in an Error State
4. Freeze - A Transparent node has Freeze turned on, suspending the execution of the node
5. Selected - Currently selected Nodes have an Aqua highlight on their border
6. Warning - Yellow Nodes are in an Warning state, meaning they may have incorrect data types
7. Background Preview - Dark Grey indicates that the geometry preview is turned off
If your Visual Program contains warning or errors, Dynamo will provide additional information about the pro blem. Any Node that is Yellow will also have a tooltip above the Name. Hover your mouse
over the tooltip to expand it.
Tip: With this tooltip information in hand, examine the upstream Nodes to see if the data type or data structure required is in error.