4.6 Geometry Conversion Methods
Dynamo geometry and Revit geometry might seem similar but are different!
Introduction
If you haven't read the excellent Dynamo Primer section on Geometry, it helps to brush up on it beforehand. Also, if your scripts include geometry make sure to include the geometry libraries in your boilerplate code!
Revit Geometry and Dynamo Geometry
As explained in the section on unwrapping Revit elements, 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 here. 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.
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':
Autodesk.Revit.DB.XYZ this can represent a point but it can *also* sometimes be a vector. Confusing, we know!
Autodesk.Revit.DB.Point 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 transaction.
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:
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.
Again, once output from the Python Script node this dynamo_line is immediately visible in the 3D background preview.
Now let's look at creating a 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:
Last updated