I am exporting the model into obj format. I want to know if it is possible to the polygon count or the number of triangles in the model before export. Does Revit provide any API ? Can I count the polygon for a element and then add them all.
No, no such API is provided ready-built.
Yes, sure you can retrieve all the element geometry, tessellate it, and sum up the total number of triangles.
You might find it easiest to do so using a custom exporter:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.1
Cheers,
Jeremy
Export your Revit project (.rvt) or family (.rfa) file to FBX format. In Revit, go to File > Export > FBX.
Open the FBX file in Microsoft 3D Viewer. Depending on the file size, it may take a little while to open. A spinning 3D box icon will indicate loading is in progress.
In the viewer, go to Tools and click on "Stats & Shading". It will list the number of triangles and vertices.
The 3D Viewer is a free download if you don't already have it in Windows 10.
Thank you for a non-programmer's answer.
The result should be the same as in using the custom exporter in the Revit API.
Here is the code
class ProfileExport : IExportContext
{
private Document document;
private Func<bool> isCanceled;
private Action<long, int> callback;
private long numTriangles;
private List<ElementId> materialIds;
private bool includeMaterials = true;
public ProfileExport(Document document, Func<bool> isCanceled, Action<long, int> callback)
{
this.isCanceled = isCanceled;
this.callback = callback;
this.document = document;
this.materialIds = new List<ElementId>();
}
public void OnPolymesh(PolymeshTopology polymesh)
{
this.numTriangles += (long)polymesh.NumberOfFacets;
}
public void Finish()
{
this.callback(this.numTriangles, this.materialIds.Count);
}
public bool IsCanceled()
{
return false;
}
public bool Start()
{
this.materialIds = new List<ElementId>();
return true;
}
public void OnRPC(RPCNode node)
{
}
public void OnLight(LightNode node)
{
}
public RenderNodeAction OnViewBegin(ViewNode node)
{
node.LevelOfDetail = 8;
return 0;
}
public void OnViewEnd(ElementId elementId)
{
}
public RenderNodeAction OnFaceBegin(FaceNode node)
{
return 0;
}
public void OnFaceEnd(FaceNode node)
{
}
public RenderNodeAction OnElementBegin(ElementId elementId)
{
return 0;
}
public void OnElementEnd(ElementId elementId)
{
}
public RenderNodeAction OnInstanceBegin(InstanceNode node)
{
return 0;
}
public void OnInstanceEnd(InstanceNode node)
{
}
public RenderNodeAction OnLinkBegin(LinkNode node)
{
return 0;
}
public void OnLinkEnd(LinkNode node)
{
}
public void OnMaterial(MaterialNode node)
{
if (this.includeMaterials)
{
if (node.MaterialId == ElementId.InvalidElementId)
{
return;
}
if (this.materialIds.Contains(node.MaterialId))
{
return;
}
this.materialIds.Add(node.MaterialId);
}
}
}
Thank you for the nice succinct sample!
I added it to The Building Coder samples in a new external command CmdTriangleCount:
https://github.com/jeremytammik/the_building_coder_samples
I tested it in a model with a single wall element with six rectangular faces, i.e., 12 triangles:
As you can see, it reports 36 faces found. Where might the 24 unexpected ones be coming from?
Cheers,
Jeremy
Thank you for confirming that it works fine for you with no additional filtering.
Maybe the two default levels in my 3D view are contributing something. I'll remove those and try again 🙂
Can't find what you're looking for? Ask the community or share your knowledge.