Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get polygon count of the project ?

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
3015 Views, 7 Replies

How to get polygon count of the project ?

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.

7 REPLIES 7
Message 2 of 8
jeremytammik
in reply to: Anonymous

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

Message 3 of 8
Homsey-CCH
in reply to: Anonymous

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.

Message 4 of 8
jeremytammik
in reply to: Homsey-CCH

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

Message 5 of 8
techXMKH9
in reply to: jeremytammik

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);
            }
        }
    }
Message 6 of 8
jeremy_tammik
in reply to: techXMKH9

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
Message 7 of 8
techXMKH9
in reply to: jeremy_tammik

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

On my end

techXMKH9_0-1628747423624.png

 

Message 8 of 8
jeremy_tammik
in reply to: techXMKH9

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report