Dynamo Python Primer
  • Take Dynamo Further 🚀
  • 1 Hello Python 🐍
    • 1.1 Why Should I Learn to Code?
    • 1.2 Python Introduction
    • 1.3 What is IronPython?
  • 2 Seeing The Bigger Picture 🔭
    • 2.1 Context Matters
    • 2.2 What is an API?
    • 2.3 The .NET Framework
    • 2.4 Object-Oriented Programming
  • 3 Getting Started 🛴
    • 3.1 Dynamo's Python Node
    • 3.2 Boilerplate Setup Code
    • 3.3 Basics: Input and Output
    • 3.4 Common Errors
  • 4 Revit-Specific Topics 🏡
    • 4.1 Introduction to Revit's API
    • 4.2 How to Read Revit's API Documentation
    • 4.3 Doc, UIDoc, App, UIApp
    • 4.4 Unwrapping Revit Elements
    • 4.5 The FilteredElementCollector
    • 4.6 Geometry Conversion Methods
    • 4.7 Working With Parameters
      • Family Parameters
      • Global Parameters
      • Project Information Parameters
      • Group Parameters
      • Built-In Parameters
    • 4.8 Working With Transactions
    • 4.9 Opening & Closing External Files
    • 4.10 Prompting UI Selection
    • 4.11 Working With Units
    • 4.12 Built-In Categories
    • 4.13 Family Acrobatics
    • 4.14 Feedback: TaskDialogs
  • 5 Glossary 📚
  • About This Primer 👋
Powered by GitBook
On this page

Was this helpful?

  1. 4 Revit-Specific Topics 🏡

4.6 Geometry Conversion Methods

Dynamo geometry and Revit geometry might seem similar but are different!

Previous4.5 The FilteredElementCollectorNext4.7 Working With Parameters

Last updated 5 years ago

Was this helpful?

Introduction

If you haven't read the excellent , it helps to brush up on it beforehand. Also, if your scripts include geometry make sure to include the geometry libraries in your !

Revit Geometry and Dynamo Geometry

As explained in the section on , Dynamo has a parallel class library to Revit. This means special conversion methods need to be used to smoothly interoperate between the two.

Dynamo's Github wiki has a page which goes into detail on this topic, which can be found . In short, it is worth being conscious of which geometry classes you're working with.

A good hint for understanding which geometry types you're working with are whether they're visible in the 3D background preview after being outputted from the node. Revit types won't be visible unless you use special conversion methods.

Conversion Methods

You can easily go between Dynamo and Revit geometry types using the conversion methods in Dynamo's API, but it's not always intuitive to know which ones to use. There is ToProtoType(),ToDSType(), ToLine(), ToPoint(), ToVector(), and ToXyz()!

The next sections will attempt to tackle the main kinds of geometry you're likely to encounter one-by-one.

Points

Let's start with something simple - points! Points are defined in 3D space by their X, Y and Z coordinates and have no measurable dimensions.

To create a Dynamo point, we need to use the Designscript Library, which is a part of Dynamo. Dynamo Points are of type Autodesk.DesignScript.Geometry.Point. If you output the below dynamo_point from a Python node it will immediately show up in Dynamo's 3D background preview.

#Boilerplate code

dynamo_point = Autodesk.DesignScript.Geometry.Point.ByCoordinates(0,0,0)
OUT = dynamo_point

That's the Dynamo point done. Now let's look at creating a Revit point. The thing is, Revit actually has two kinds of 'points':

#Boilerplate code
revit_xyz = XYZ(0,0,0) #A Revit XYZ
#The Point class is created using an XYZ object
revit_point = Point.Create(revit_xyz)
OUT = revit_xyz, revit_point

We can output our XYZ and our Point from the Python Script node, but they won't be visible in the Dynamo geometry preview unless we convert them to Dynamo types like so:

#Boilerplate code
revit_xyz = XYZ(0,0,0)
revit_point = Point.Create(revit_xyz)
OUT = revit_xyz.ToPoint(), revit_point.ToProtoType()

Lines / Curves

As before, let's look at the Dynamo classes first: Dynamo has two 'line-like' geometry classes. It's worth disambiguating the two to see how they differ.

  • Autodesk.DesignScript.Geometry.Line this is more like a 'classic' straight line, which has a start point and an end point.

  • Autodesk.DesignScript.Geometry.Curve Dynamo's curve class can be a bit more ambitious than a simple straight line. It can handle complex surfaces or UV coordinates.

To keep this example simple, we'll show how to create a straightforward Dynamo line below. First we'll create to Dynamo points, then use these as the start and end points defining our line.

#Boilerplate Code
dynamo_point_1 = Autodesk.DesignScript.Geometry.Point.ByCoordinates(0,0,0)
dynamo_point_2 = Autodesk.DesignScript.Geometry.Point.ByCoordinates(10,10,0)
dynamo_line = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(dynamo_point_1, dynamo_point_2)
OUT = dynamo_line

Again, once output from the Python Script node this dynamo_line is immediately visible in the 3D background preview.

#Boilerplate Code
revit_xyz_1 = XYZ(0,0,0)
revit_xyz_2 = XYZ(10,10,0)
revit_line = Line.CreateBound(revit_xyz_1, revit_xyz_2)
OUT = revit_line

Again, this won't be visible in the Dynamo geometry preview unless we convert it to a Dynamo geometry type, using .ToProtoType(), like so:

#Boilerplate Code
revit_xyz_1 = XYZ(0,0,0)
revit_xyz_2 = XYZ(10,10,0)
revit_line = Line.CreateBound(revit_xyz_1, revit_xyz_2)
OUT = revit_line.ToProtoType()

this can represent a point but it can *also* sometimes be a vector. Confusing, we know!

this is also a Revit point, but less ambiguously so.

Even though we're creating Revit objects here, in this case we don't need to wrap them in a .

Now let's look at creating a :

Dynamo Primer section on Geometry
boilerplate code
unwrapping Revit elements
here
Autodesk.Revit.DB.XYZ
Autodesk.Revit.DB.Point
transaction
Revit line