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

Definitely follow the advice on the thread @chuongmep 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;
5 Likes