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