public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; // retrieve selected floors, or all floors, if nothing is selected: 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 = GetFloorBoundaryPolygons(floors, opt); int n = polygons.Count; Debug.Print( "{0} boundary loop{1} found.", n, Util.PluralSuffix(n)); Creator creator = new Creator(doc); using (Transaction t = new Transaction(doc)) { t.Start("Draw Slab Boundaries"); creator.DrawPolygons(polygons); t.Commit(); } return(Result.Succeeded); }
/// <summary> /// Original implementation published November 17, 2008: /// http://thebuildingcoder.typepad.com/blog/2008/11/wall-elevation-profile.html /// </summary> public Result Execute1( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; List <Element> walls = new List <Element>(); if (!Util.GetSelectedElementsOrAll( walls, uidoc, typeof(Wall))) { Selection sel = uidoc.Selection; message = (0 < sel.GetElementIds().Count) ? "Please select some wall elements." : "No wall elements found."; return(Result.Failed); } Options opt = app.Application.Create.NewGeometryOptions(); List <List <XYZ> > polygons = GetWallProfilePolygons(walls, opt); int n = polygons.Count; Debug.Print( "{0} boundary loop{1} found.", n, Util.PluralSuffix(n)); Creator creator = new Creator(doc); using (Transaction tx = new Transaction(doc)) { tx.Start("Draw Wall Elevation Profile Model Lines"); creator.DrawPolygons(polygons); tx.Commit(); } return(Result.Succeeded); }
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); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; List <Element> walls = new List <Element>(); if (!Util.GetSelectedElementsOrAll( walls, uidoc, typeof(Wall))) { Selection sel = uidoc.Selection; message = (0 < sel.GetElementIds().Count) ? "Please select some wall elements." : "No wall elements found."; return(Result.Failed); } Options opt = app.Application.Create.NewGeometryOptions(); List <List <XYZ> > polygons = CmdWallProfile.GetWallProfilePolygons( walls, opt); int i = 0, n = polygons.Count; double[] areas = new double[n]; double d, a, maxArea = 0.0; XYZ normal; foreach (List <XYZ> polygon in polygons) { GetPolygonPlane(polygon, out normal, out d, out a); if (Math.Abs(maxArea) < Math.Abs(a)) { maxArea = a; } areas[i++] = a; #if DEBUG // transform the 3D polygon into a horizontal plane // so we can use the 2D GetSignedPolygonArea() and // compare its results with the 3D calculation. // todo: compare the relative speed of // transforming 3d to 2d and using 2d area // calculation versus direct 3d area calculation. Transform t = GetTransformToZ(normal); List <XYZ> polygonHorizontal = ApplyTransform(polygon, t); List <UV> polygon2d = CmdSlabBoundaryArea.Flatten( polygonHorizontal); double a2 = CmdSlabBoundaryArea.GetSignedPolygonArea( polygon2d); Debug.Assert(Util.IsEqual(a, a2), "expected same area from 2D and 3D calculations"); #endif } 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 wall" : "")); } Creator creator = new Creator(doc); using (Transaction tx = new Transaction(doc)) { tx.Start("Draw wall profile loops"); creator.DrawPolygons(polygons); tx.Commit(); } return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; // retrieve selected floors, or all floors, if nothing is selected: List<Element> floors = new List<Element>(); if( !Util.GetSelectedElementsOrAll( floors, uidoc, typeof( Floor ) ) ) { Selection sel = uidoc.Selection; message = ( 0 < sel.Elements.Size ) ? "Please select some floor elements." : "No floor elements found."; return Result.Failed; } Options opt = app.Application.Create.NewGeometryOptions(); List<List<XYZ>> polygons = GetFloorBoundaryPolygons( floors, opt ); int n = polygons.Count; Debug.Print( "{0} boundary loop{1} found.", n, Util.PluralSuffix( n ) ); Creator creator = new Creator( doc ); using( Transaction t = new Transaction( doc ) ) { t.Start( "Draw Slab Boundaries" ); creator.DrawPolygons( polygons ); t.Commit(); } return Result.Succeeded; }
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.Elements.Size ) ? "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" : "" ) ); } Creator creator = new Creator( doc ); creator.DrawPolygons( polygons ); return Result.Succeeded; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; List<Element> walls = new List<Element>(); if( !Util.GetSelectedElementsOrAll( walls, uidoc, typeof( Wall ) ) ) { Selection sel = uidoc.Selection; message = ( 0 < sel.Elements.Size ) ? "Please select some wall elements." : "No wall elements found."; return Result.Failed; } Options opt = app.Application.Create.NewGeometryOptions(); List<List<XYZ>> polygons = GetWallProfilePolygons( walls, opt ); int n = polygons.Count; Debug.Print( "{0} boundary loop{1} found.", n, Util.PluralSuffix( n ) ); Creator creator = new Creator( doc ); creator.DrawPolygons( polygons ); return Result.Succeeded; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; List<Element> walls = new List<Element>(); if( !Util.GetSelectedElementsOrAll( walls, uidoc, typeof( Wall ) ) ) { Selection sel = uidoc.Selection; message = ( 0 < sel.Elements.Size ) ? "Please select some wall elements." : "No wall elements found."; return Result.Failed; } Options opt = app.Application.Create.NewGeometryOptions(); List<List<XYZ>> polygons = CmdWallProfile.GetWallProfilePolygons( walls, opt ); int i = 0, n = polygons.Count; double[] areas = new double[n]; double d, a, maxArea = 0.0; XYZ normal; foreach( List<XYZ> polygon in polygons ) { GetPolygonPlane( polygon, out normal, out d, out a ); if( Math.Abs( maxArea ) < Math.Abs( a ) ) { maxArea = a; } areas[i++] = a; #if DEBUG // transform the 3D polygon into a horizontal plane // so we can use the 2D GetSignedPolygonArea() and // compare its results with the 3D calculation. // todo: compare the relative speed of // transforming 3d to 2d and using 2d area // calculation versus direct 3d area calculation. Transform t = GetTransformToZ( normal ); List<XYZ> polygonHorizontal = ApplyTransform( polygon, t ); List<UV> polygon2d = CmdSlabBoundaryArea.Flatten( polygonHorizontal ); double a2 = CmdSlabBoundaryArea.GetSignedPolygonArea( polygon2d ); Debug.Assert( Util.IsEqual( a, a2 ), "expected same area from 2D and 3D calculations" ); #endif } 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 wall" : "" ) ); } Creator creator = new Creator( doc ); creator.DrawPolygons( polygons ); return Result.Succeeded; }