Dynamo
Primer for v2.0
English
English
  • About
  • Introduction
    • What is Dynamo & How Does It Work?
    • Primer User Guide, Dynamo Community & Platform
  • Setup for Dynamo
  • User Interface
    • Workspace
    • Library
  • Nodes and Wires
  • Essential Nodes & Concepts
    • Index of Nodes
    • Geometry for Computational Design
      • Geometry Overview
      • Vector, Plane & Coordinate System
      • Points
      • Curves
      • Surfaces
      • Solids
      • Meshes
    • The Building Blocks of Programs
      • Data
      • Math
      • Logic
      • Strings
      • Color
    • Designing with Lists
      • What's a List
      • Working with Lists
      • Lists of Lists
      • n-Dimensional Lists
    • Dictionaries in Dynamo
      • What is a Dictionary
      • Dictionary Nodes
      • Dictionaries in Code Blocks
      • Revit Use-Cases
  • Custom Nodes & Packages
    • Custom Nodes
      • Custom Node Introduction
      • Creating a Custom Node
      • Publishing to Your Library
    • Packages
      • Package Introduction
      • Package Case Study - Mesh Toolkit
      • Developing a Package
      • Publishing a Package
      • Zero-Touch Importing
  • Dynamo for Revit
    • The Revit Connection
    • Selecting
    • Editing
    • Creating
    • Customizing
    • Documenting
  • Dynamo for Civil 3D
    • The Civil 3D Connection
    • Getting Started
    • Node Library
    • Sample Workflows
      • Roads
        • Light Pole Placement
      • Land
        • Service Placement
      • Utilities
        • Rename Structures
      • Rail
        • Clearance Envelope
      • Surveying
        • Point Group Management
    • Advanced Topics
      • Object Binding
      • Python and Civil 3D
    • Dynamo Player
    • Useful Packages
    • Resources
  • Dynamo in Forma Beta
    • Set Up Dynamo Player in Forma
    • Add and Share Graphs in Dynamo Player
    • Run Graphs in Dynamo Player
    • Dynamo compute service differences with Desktop Dynamo
  • Coding in Dynamo
    • Code Blocks and DesignScript
      • What's a Code Block
      • DesignScript Syntax
      • Shorthand
      • Functions
    • Geometry with DesignScript
      • DesignScript Geometry Basics
      • Geometric Primitives
      • Vector Math
      • Curves: Interpolated and Control Points
      • Translation, Rotation, and Other Transformations
      • Surfaces: Interpolated, Control Points, Loft, Revolve
      • Geometric Parameterization
      • Intersection and Trim
      • Geometric Booleans
      • Python Point Generators
    • Python
      • Python Nodes
      • Python and Revit
      • Setup Your Own Python Template
    • Language Changes
  • Best Practices
    • Graph Strategies
    • Scripting Strategies
    • Scripting Reference
    • Managing Your Program
    • Efficiently Working With Large Data Sets In Dynamo
  • Sample Workflows
    • Getting Started Workflows
      • Parametric Vase
      • Attractor Points
    • Concept Index
  • Developer Primer
    • Build Dynamo from Source
      • Build DynamoRevit from Source
      • Managing and Updating Dependencies in Dynamo
    • Developing for Dynamo
      • Getting Started
      • Zero-Touch Case Study - Grid Node
      • Executing Python Scripts in Zero-Touch Nodes (C#)
      • Going Further with Zero-Touch
      • Advanced Dynamo Node Customization
      • Using COM (interop) types in Dynamo Packages
      • NodeModel Case Study - Custom UI
      • Updating your Packages and Dynamo Libraries for Dynamo 2.x
      • Updating your Packages and Dynamo Libraries for Dynamo 3.x
      • Extensions
      • Defining Custom Package Organization for Dynamo 2.0+
      • Dynamo Command Line Interface
      • Dynamo Integration
      • Developing For Dynamo For Revit
      • Publish a Package
      • Build a Package from Visual Studio
      • Extensions as Packages
    • Pull Requests
    • Testing Expectations
    • Examples
  • Appendix
    • Frequently Asked Questions
    • Visual Programming and Dynamo
    • Resources
    • Release Notes
    • Useful Packages
    • Example Files
    • Host Integration Map
    • Download PDF
    • Dynamo Keyboard Shortcuts
Powered by GitBook
On this page
  • Working with Lists
  • Query
  • Action
  • Exercise
  • List Operations
  • List.Count
  • List.GetItemAtIndex
  • List.Reverse
  • List.ShiftIndices
  • List.FilterByBooleanMask
Edit on GitHub
Export as PDF
  1. Essential Nodes & Concepts
  2. Designing with Lists

Working with Lists

PreviousWhat's a ListNextLists of Lists

Last updated 2 months ago

Working with Lists

Now that we've established what a list is, let's talk about operations we can perform on it. Imagine a list as a deck of playing cards. A deck is the list and each playing card represents an item.

Query

What queries can we make from the list? This accesses existing properties.

  • Number of cards in the deck? 52.

  • Number of suits? 4.

  • Material? Paper.

  • Length? 3.5" or 89mm.

  • Width? 2.5" or 64mm.

Action

What actions can we perform on the list? This changes the list based on a given operation.

  • We can shuffle the deck.

  • We can sort the deck by value.

  • We can sort the deck by suit.

  • We can split the deck.

  • We can partition the deck by dealing out individual hands.

  • We can select a specific card in the deck.

All of the operations listed above have analogous Dynamo nodes for working with lists of generic data. The lessons below will demonstrate some of the fundamental operations we can perform on lists.

Exercise

List Operations

Download the example file by clicking on the link below.

A full list of example files can be found in the Appendix.

The image below is the base graph which we are drawing lines between two circles to represent basic list operations. We'll explore how to manage data within a list and demonstrate the visual results through the list actions below.

  1. Begin with a Code Block with a value of 500;

  2. Plug into the x input of a Point.ByCoordinates node.

  3. Plug the node from the previous step into the origin input of a Plane.ByOriginNormal node.

  4. Using a Circle.ByPlaneRadius node, plug the node from the previous step into the plane input.

  5. Using Code Block, designate a value of 50; for the radius. This is the first circle we'll create.

  6. With a Geometry.Translate node, move the circle up 100 units in the Z direction.

  7. With a Code Block node, define a range of ten numbers between 0 and 1 with this line of code: 0..1..#10;

  8. Plug the code block from the previous step into the param input of two Curve.PointAtParameter nodes. Plug Circle.ByPlaneRadius into the curve input of the top node, and Geometry.Translate into the curve input of the node beneath it.

  9. Using a Line.ByStartPointEndPoint, connect the two Curve.PointAtParameter nodes.

List.Count

Download the example file by clicking on the link below.

A full list of example files can be found in the Appendix.

The List.Count node is straightforward: it counts the number of values in a list and returns that number. This node gets more nuanced as we work with lists of lists, but we'll demonstrate that in the coming sections.

  1. The **List.Count ****** node returns the number of lines in the Line.ByStartPointEndPoint node. The value is 10 in this case, which agrees with the number of points created from the original Code Block node.

List.GetItemAtIndex

Download the example file by clicking on the link below.

A full list of example files can be found in the Appendix.

List.GetItemAtIndex is a fundamental way to query an item in the list.

  1. First, Right click on Line.ByStartPointEndPoint node to switch off its preview.

  2. Using the List.GetItemAtIndex node, we are selecting index "0", or the first item in the list of lines.

Change slider value between 0 and 9 to select different item using List.GetItemAtIndex.

List.Reverse

Download the example file by clicking on the link below.

A full list of example files can be found in the Appendix.

List.Reverse reverses the order of all of the items in a list.

  1. To properly visualize the reversed list of lines, create more lines by changing the Code Block to 0..1..#50;

  2. Duplicate the Line.ByStartPointEndPoint node, insert a List.Reverse node in between Curve.PointAtParameter and the second Line.ByStartPointEndPoint

  3. Use Watch3D nodes to preview two different results. The first one shows the result without a reversed list. The lines connect vertically to neighboring points. The reversed list, however, will connect all of the points to the opposing order in the other list.

List.ShiftIndices

Download the example file by clicking on the link below.

A full list of example files can be found in the Appendix.

List.ShiftIndices is a good tool for creating twists or helical patterns, or any other similar data manipulation. This node shifts the items in a list a given number of indices.

  1. In the same process as the reverse list, insert a List.ShiftIndices into the Curve.PointAtParameter and Line.ByStartPointEndPoint.

  2. Using a Code Block, designated a value of "1" to shift the list one index.

  3. Notice that the change is subtle, but all of the lines in the lower Watch3D node have shifted one index when connecting to the other set of points.

By changing to Code Block to a larger value, "30" for example, we notice a significant difference in the diagonal lines. The shift is working like a camera's iris in this case, creating a twist in the original cylindrical form.

List.FilterByBooleanMask

Download the example file by clicking on the link below.

A full list of example files can be found in the Appendix.

List.FilterByBooleanMask will remove certain items based on a list of booleans, or values reading "true" or "false".

In order to create a list of values reading "true" or "false", we need to a little more work...

  1. Using a Code Block, define an expression with the syntax: 0..List.Count(list);. Connect the Curve.PointAtParameter node to the list input. We'll walk through this setup more in the code block chapter, but the line of code in this case is giving us a list representing each index of the Curve.PointAtParameter node.

  2. Using a %** (modulus)** node, connect the output of the code block into the x input, and a value of 4 into the y input. This will give us the remainder when dividing the list of indices by 4. Modulus is a really helpful node for pattern creation. All values will read as the possible remainders of 4: 0, 1, 2, 3.

  3. From the %** (modulus)** node, we know that a value of 0 means that the index is divisible by 4 (0,4,8,etc...). By using a == node, we can test for the divisibility by testing it against a value of "0".

  4. The Watch node reveals just this: we have a true/false pattern which reads: true,false,false,false....

  5. Using this true/false pattern, connect to the mask input of two List.FilterByBooleanMask nodes.

  6. Connect the Curve.PointAtParameter node into each list input for the List.FilterByBooleanMask.

  7. The output of Filter.ByBooleanMask reads "in" and "out". "In" represents values which had a mask value of "true" while "out" represents values which had a value of "false". By plugging the "in" outputs into the startPoint and endPoint inputs of a Line.ByStartPointEndPoint node, we've created a filtered list of lines.

  8. The Watch3D node reveals that we have fewer lines than points. We've selected only 25% of the nodes by filtering only the true values!

Photo by

Christian Gidlöf
7KB
List-Operations.dyn
8KB
List-Count.dyn
8KB
List-GetItemAtIndex.dyn
8KB
List-Reverse.dyn
8KB
List-ShiftIndices.dyn
11KB
List-FilterByBooleanMask.dyn
cards
Count
Exercise
Exercise
Exercise
Exercise