public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication app = commandData.Application;
UIDocument uidoc = app.ActiveUIDocument;
Document doc = uidoc.Document;
List <Element> floors = new List <Element>();
if (!Util.GetSelectedElementsOrAll(
floors, uidoc, typeof(Floor)))
{
Selection sel = uidoc.Selection;
message = (0 < sel.GetElementIds().Count)
? "Please select some floor elements."
: "No floor elements found.";
return(Result.Failed);
}
Options opt = app.Application.Create.NewGeometryOptions();
List <List <XYZ> > polygons
= CmdSlabBoundary.GetFloorBoundaryPolygons(
floors, opt);
List <List <UV> > flat_polygons
= Flatten(polygons);
int i = 0, n = flat_polygons.Count;
double[] areas = new double[n];
double a, maxArea = 0.0;
foreach (List <UV> polygon in flat_polygons)
{
a = GetSignedPolygonArea(polygon);
if (Math.Abs(maxArea) < Math.Abs(a))
{
maxArea = a;
}
areas[i++] = a;
}
Debug.Print(
"{0} boundary loop{1} found.",
n, Util.PluralSuffix(n));
for (i = 0; i < n; ++i)
{
Debug.Print(
" Loop {0} area is {1} square feet{2}",
i,
Util.RealString(areas[i]),
(areas[i].Equals(maxArea)
? ", outer loop of largest floor slab"
: ""));
}
using (Transaction t = new Transaction(doc))
{
t.Start("Draw Polygons");
Creator creator = new Creator(doc);
creator.DrawPolygons(polygons);
t.Commit();
}
return(Result.Succeeded);
}