Zero Touch Node - convert Autodesk.Revit.DB.Solid to Autodesk.DesignScript.Geometry.Solid

Hi all,
I’m having difficulties converting between a Autodesk.Revit.DB.Solid to a Autodesk.DesignScript.Geometry.Solid in a ZeroTouch node.

I’m extracting data from a curtain panel. First I extract the get_Geometry(), then I want to iterate over it and get the faces, edges etc…

The main problem is that DesignScript doesn’t allow me access to .Faces, while Revit.DB does.

The way to find the FaceArray in theory is (mainly looking at Revit Lookup) through the GetInstanceGeometry, GetSymbolGeometry, or SymbolGeometry, all of which return a Solid.

So far this is my relevant code:

GeometryElement panelGeometry = panel.get_Geometry(options); // get geometry
    foreach (Autodesk.Revit.DB.Solid geometry in panelGeometry) // iterate
    {
        FaceArray panelFaces = geometry.Faces; // get all faces

Nevertheless, there are 2 issues with this exploration that are bothering me:

  1. Why does a rectangular panel element have 8 faces and not 6? (attached image)

  2. How to correctly convert the Solid in my code, so that I can access FaceArray, without getting the error displayed in Dynamo (attached error msg image)?
    error

I’ve tried looking online a lot, and tried various combinations of extracting the GetInstanceGeometry or trying to cast to different types, but without luck.
Maybe I need to loop with a different Type and only then filter check for a Solid match? Not sure…

Any help would be appreciated.
Thanks.

For point 1, if you count the edges of the faces, 4 of them should be triangles (the larger faces). Can you confirm?
For point 2, a GeometryInstance is still a collection of GeometryObjects, so you need to “drill down one more level” so to speak and treat the GeometryInstance as a GeometryElement.

1 Like

@Paolo_Emilio_Serra1
Thanks for the reply.
I tried what you suggested and did make some headway, mainly from exploring better the Solid Class.
https://www.revitapidocs.com/2015/7a3b5ac1-c66d-9f81-a11d-9bcd4e026295.htm

So now I drill correctly down to the instances, but then I still can’t figure out how to translate Autodesk.Revit.DB.Solid to a Autodesk.DesignScript.Geometry.Solid, because the error I’m getting is:
error

I can’t really cast one to the other… I was thinking there might exist some .ToPrototype() method like in Dynamo-Python, to convert and unwrap or wrap objects, but I don’t know if that’s relevant in Visual Studio and C#…

Any ideas…?

@yafim.simanovsky Have you tried looking into the Dynamo for Revit source code? https://github.com/DynamoDS/DynamoRevit/blob/master/src/Libraries/RevitNodes/GeometryConversion/ProtoToRevitSolid.cs

What exactly are you trying to do? In your OP question you state that you are trying to convert a Revit API Solid to a ProtoGeometry Solid, yet your thread only discusses face conversion?

Which is it?

For Faces you can only convert them to ProtoGeometry Surface using ToProtoType() (so yeah, it does apply in C#, the language is irrelevant; its simply a conversion method which recreates a geometry object from Dynamos geometry engine). Converting to a ProtoGeometry Face isn’t possible AFAIK, and I’ve never seen any example of a conversion from Revit API Face to ProtoGeometry Face.

For Solid you can still use ToProtoType().

Also, its impossible to cast a API Solid or Face to the equivalent type in the ProtoGeometry - you can only cast from an inherited class (or interface) to a subclass - its not a magic wand which can convert any type to any other type even from different libraries - a good analogy is trying to cast lead into gold; its never going to work. That’s why the conversion methods exist as they save the developer from having to rebuild/instantiate the respective geometry from scratch using the other geometry library (which behind the scenes is exactly what this method does which is not the same thing as casting which operates on the original object, it doesn’t instantiate a new one).

1 Like

Hi,
Thanks.
@Thomas_Mahon I understand what you mean. In my original post I mistakenly referred to Solid, sorry.
The more general question was how to get Autodesk.Revit.DB elements to be represented by Autodesk.DesignScript.Geometry, regardless of if it’s a Solid, Face, or Edge.

In all of these cases there isn’t a direct way to convert. I can “drill down” from Solid to Edge but at any point if I try to output anything to Dynamo, I get errors with this conversion problem.

I’ll take a look at the source code and methods you describe and come back if needed.
Thanks guys :slight_smile:

The most efficient or accurate way i can think of is, if it is just a simple shape like a square or circle you can just to ToProtoType() method and cast it to its relevant geometry, else you would have to do a shape slicing (to simple geometries), and use ToProtoType() method, and then join them via solid union. If thats what you are asking

Hi all,
After looking at the source code (thanks @Paolo_Emilio_Serra1) I was missing the RevitNodes.dll reference, therefore could not use the Revit.GeometryConversion namespace.
Once finding that, I was able to use .ToPrototype() and achieve conversion like I wanted.

Thank you.

2 Likes