How to get polygon count of the project ?

Anonymous

How to get polygon count of the project ?

Anonymous
Not applicable

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.

0 Likes
Reply
3,003 Views
7 Replies
Replies (7)

jeremytammik
Autodesk
Autodesk

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

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

Homsey-CCH
Enthusiast
Enthusiast

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.

0 Likes

jeremytammik
Autodesk
Autodesk

Thank you for a non-programmer's answer.

 

The result should be the same as in using the custom exporter in the Revit API.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

techXMKH9
Contributor
Contributor

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);
            }
        }
    }
0 Likes

jeremy_tammik
Autodesk
Autodesk

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

 

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/C...

 

I tested it in a model with a single wall element with six rectangular faces, i.e., 12 triangles:

 

tbc_samples_triangle_count.png

 

  

As you can see, it reports 36 faces found. Where might the 24 unexpected ones be coming from?

 

Cheers,

 

Jeremy

  

 

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

techXMKH9
Contributor
Contributor

@jeremy_tammik I do not know why you are getting that. Maybe some hidden elements.

On my end

techXMKH9_0-1628747423624.png

 

0 Likes

jeremy_tammik
Autodesk
Autodesk

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 🙂

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes