Autodesk.DesignScript.Geometry.Surface to Autodesk.Revit.DB.Face?

Hi guys,
I’m trying to convert Autodesk.DesignScript.Geometry.Surface to Autodesk.Revit.DB.Face but i can’t.
My code (seem failed):

        IList<GeometryObject> geometryObjects = Autodesk.DesignScript.Geometry.surface.ToRevitType();
        Autodesk.Revit.DB.Face f = geometryObjects.FirstOrDefault() as Autodesk.Revit.DB.Face;

How should i do to get Autodesk.Revit.DB.Face from Autodesk.DesignScript.Geometry.Surface ?
Thank in advanced!

You can see a same problem in this.

1 Like

Definitely follow the advice on the thread @chuongpqvn linked to - if you’re in the Revit API context, stay there and don’t mix in ProtoGeometry calls if you don’t need to as its just bad programming IMO.

However, if you are inputting ‘faces’ selected in Dynamo from from a Revit Element then it represents the face as a ProtoGeometry Surface. They are not the same thing, and there is no conversion method to answer your question. Instead, ProtoGeometry entities which derived from Revit elements have a Tags property which allows the developer to get the original reference back to the Revit API Face. Hence ToRevitType() is not the way to go. Unfortunately, there’s no documentation on Tags so its all guess work and information from community/Dynamo team which revealed their inner workings.

Example - remember this only works if the Surface has derived from a Revit Element. If you just create a surface from scratch in Dynamo its impossible to convert it to a Revit API Face (as its impossible to instantiate a Face via the Revit API):

var tags = protoSurface.Tags;

var faceReference = (Reference)tags.LookupTag("RevitFaceReference");

Also, your syntax is incorrect and wont work. You cant qualify a instance of a type and the compiler will throw an exception. Your first line should look something like this:

`var geometryObjects = surface.ToRevitType();

Finally, if you want to the Face rather than the Reference then you need the element from where the face originated:

var tags = protoSurface.Tags;
var faceReference = (Reference)tags.LookupTag("RevitFaceReference");
var face = elementOwner.GetGeometryObjectFromReference(faceReference) as Face;
4 Likes

Hi @Thomas_Mahon
Thank for your explanation. It’s helpful for me.
So, I thought of another way to solve my problem.
This is my input will be Autodesk.Revit.DB.PlanarFace.
After that, i want to get host element of Autodesk.Revit.DB.PlanarFace by code
Element element = Doc.GetElement(planarface.Reference.ElementId);

But when run node in dynamo, i got error.
It’s a pity that i can’t debug zero touch to know issue.
Is that line code above true?
Many thanks!