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 calculate model group elements area using Revit API

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
1807 Views, 10 Replies

How to calculate model group elements area using Revit API

Hi All,

 

          I am new to use RevIT API . I need to know about following things :

1) How to calculate model group elements area using Revit API ?

2) Is this possible using ExtrusionAnalyzer ? If yes then how we can achieve this ?

     As i know ExtrusionAnalyzer needs a solid type object to draw the shadow, correct me if i am wrong.

From a model group i have extracted the elements that belongs to the model group. Now the problem is that extracted elements can have different types not necessarily solid type.

 

Let me know if anyone have any idea about this.

 

Thanks

10 REPLIES 10
Message 2 of 11
jeremytammik
in reply to: Anonymous

Dear Vyom Dixit,

 

It really all depends on what type of elements you are talking about.

 

Best regards,

 

Jeremy



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

Message 3 of 11
Anonymous
in reply to: jeremytammik

Hi Jeremy,

 

               Thanks to your response. Regarding to question, I have model group that can have some equipments like Freezer,WorkTable or any Specility Equipment,furniture etc. I want to calculate total occupied areas of these equipments that belongs to the model group. Can you give me any way to achieve this ?

 

 

Thanks

Vyom Dixit

Message 4 of 11
jeremytammik
in reply to: Anonymous

Dear Vyom Dixit,

 

Once you put it like that, I understand what you need.

 

I have in fact solved that exact issue, for my room editor app, to determine boundary loops for equipment and furniture family instances:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.21

 

In that case, I did in fact use the ExtrusionAnalyzer class to determine the closed loops.

 

In my case, though, it would probably have been easier just using the 2D plan view of the family instances.

 

For areas, though, the extrusion analyser is probably the right way to go.

 

At least it is a very generic solution.

 

As you say, though, it does require a solid.

 

Cheers,

 

Jeremy



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

Message 5 of 11
jeremytammik
in reply to: jeremytammik

Dear Vyom Dixit,

 

I expanded a bit on my initial answer and published a summary of this thread on The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/2015/02/family-instance-area-and-auto-loading-a-project-fil...

 

You might want to check out the enhanced answer there as well.

 

Thank you!

 

Cheers,

 

Jeremy



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

Message 6 of 11
Anonymous
in reply to: jeremytammik

Hi Jeremy,

 

               Many thanks to your quick response.I have reviewed your post as you mentioned in your last reply. In my case, i don't think extrusion analyser approach would work for all the model group elements becuase i am getting exception to union some solids that belong to family instance. So, i want to use that approach you have mentioned in your post : "using 2D plan view of the family instances". Can you suggest this approach in steps not the code ?

 

Thanks

Vyom Dixit

Message 7 of 11
jeremytammik
in reply to: Anonymous

Dear Vyom Dixit,

 

Please note that I ran into such exceptions when performing the Boolean unions as well and added exception handlers to take care of those cases anyway.

 

The extrusion handler is fed with 3D solids retrieved from the family instances in a 3D view.

 

If you retrieve their geometry via a 2D plan view instead, you will get other results and other geometry, presumably mainly consisting of curves.

 

  • Element.Geometry Property 
  • Options Class
  • Options.View Property
  • The view used for geometry extraction.

 

Grab those curves and do what thou wilt.

 

Cheers,

 

Jeremy



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

Message 8 of 11
Anonymous
in reply to: jeremytammik

Hi Jeremy,

 

             I followed as you suggested, but the area i am getting is not correct. I am putting here my code block, suggest me where i am missing something or doing anything wrong in the approach. The current view of the revit model is plan view. Please have a look on below code and suggest me where i am doing anything not correctly.

 

I have taken reference from your below post -

http://thebuildingcoder.typepad.com/blog/2008/12/2d-polygon-areas-and-outer-loop.html

 

 

Code Block :

 

public static double GetElementOccupiedAreaByGeometry(Document doc, Element component)
        {
            List<List<UV>> polygons = new List<List<UV>>();
            double elmentArea = 0;
            Options geomOption = doc.Application.Create.NewGeometryOptions();
            geomOption.View = doc.ActiveView;
            GeometryElement geoElement = component.get_Geometry(geomOption);
            foreach (GeometryObject geoObject in geoElement)
            {
                if (geoObject.GetType() == typeof(GeometryInstance))
                {
                    GeometryInstance geomInst = geoObject as GeometryInstance;
                    foreach (GeometryObject gObject in geomInst.GetInstanceGeometry())
                    {
                        if (gObject is Arc)
                        {
                            Arc arc = gObject as Arc;
                            if (arc != null)
                            {
                                List<XYZ> points = arc.Tessellate().ToList();
                                if (points.Count > 0)
                                {
                                    polygons.Add(GetPolygon(points));
                                }
                            }
                        }
                    }

                }
            }

            // get signed polygon area by each polygon UV list.
            foreach (List<UV> polygon in polygons)
            {
                double area = GetSignedPolygonArea(polygon);

                if (Math.Abs(elmentArea) < Math.Abs(area))
                {
                    elmentArea = area;
                }
            }
            return elmentArea;
        }

        private static List<UV> GetPolygon(List<XYZ> polygon)
        {
            List<UV> uvGroup = new List<UV>();
            foreach (XYZ point in polygon)
            {
                uvGroup.Add(new UV(point.X, point.Y));
            }
            return uvGroup;

        }

       

        // this algo taken from "http://thebuildingcoder.typepad.com/blog/2008/12/2d-polygon-areas-and-outer-loop.html"
        private static double GetSignedPolygonArea(List<UV> p)
        {
            int n = p.Count;
            double sum = p[0].U * (p[1].V - p[n - 1].V);
            for (int i = 1; i < n - 1; ++i)
            {
                sum += p[i].U * (p[i + 1].V - p[i - 1].V);
            }
            sum += p[n - 1].U * (p[0].V - p[n - 2].V);
            return 0.5 * sum;
        }

 

 

Please let me know your suggestions.

 

Thanks

Vyom Dixit

Message 9 of 11
jeremytammik
in reply to: Anonymous

Dear Vyom Dixit,

 

What is not correct? What is the result, and what are you expecting? You are aware that all Revit database length units are in feet, I hope?

 

Cheers,

 

Jeremy



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

Message 10 of 11
Anonymous
in reply to: jeremytammik

Hi Jeremy,

 

 

              My revit model units are in feet and i am also handling unit conversion. I just want to confirm that Are we fine with only element

"Arc" type object ( or we need to cosider Line/Solid type object also ) while traversing the element geometry. As i am trying to get area of  speciality equipment like - "Hand Sink". It's dimension is as mentioned below. So area should be accordingly.

Length = 1feet 2 inch

width = 0 feet 10 inch

 

 

Thanks

Vyom Dixit

Message 11 of 11
jeremytammik
in reply to: Anonymous

Dear Vyom Dixit,

 

The easiest way to handle arcs and other curved elements is to tessellate them into straight line segments.

 

The Revit API does that for you automatically, if you want.

 

Techniques for handling this are demonstrated in multiple places on The Building Coder, including the sequence of posts that I already pointed out to you.

 

Cheers,

 

Jeremy



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

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

Post to forums  

Rail Community


Autodesk Design & Make Report