/// <summary> /// Return a string for a bounding box /// which may potentially be null /// with its coordinates formatted to two /// decimal places. /// </summary> public static string BoundingBoxString2(BoundingBoxXYZ bb) { return(null == bb ? "<null>" : Util.BoundingBoxString(bb)); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; FilteredElementCollector sheets = new FilteredElementCollector(doc); sheets.OfClass(typeof(ViewSheet)); // map with key = sheet element id and // value = list of viewport element ids: Dictionary <ElementId, List <ElementId> > mapSheetToViewport = new Dictionary <ElementId, List <ElementId> >(); // map with key = viewport element id and // value = sheet element id: Dictionary <ElementId, ElementId> mapViewportToSheet = new Dictionary <ElementId, ElementId>(); foreach (ViewSheet sheet in sheets) { //int n = sheet.Views.Size; // 2014 ISet <ElementId> viewIds = sheet.GetAllPlacedViews(); // 2015 int n = viewIds.Count; Debug.Print( "Sheet {0} contains {1} view{2}: ", Util.ElementDescription(sheet), n, Util.PluralSuffix(n)); ElementId idSheet = sheet.Id; int i = 0; foreach (ElementId id in viewIds) { View v = doc.GetElement(id) as View; BoundingBoxXYZ bb; bb = v.get_BoundingBox(doc.ActiveView); Debug.Assert(null == bb, "expected null view bounding box"); bb = v.get_BoundingBox(sheet); Debug.Assert(null == bb, "expected null view bounding box"); Element viewport = GetViewport(sheet, v); // null if not in active view: bb = viewport.get_BoundingBox(doc.ActiveView); BoundingBoxUV outline = v.Outline; Debug.WriteLine(string.Format( " {0} {1} bb {2} outline {3}", ++i, Util.ElementDescription(v), (null == bb ? "<null>" : Util.BoundingBoxString(bb)), Util.BoundingBoxString(outline))); if (!mapSheetToViewport.ContainsKey(idSheet)) { mapSheetToViewport.Add(idSheet, new List <ElementId>()); } mapSheetToViewport[idSheet].Add(v.Id); Debug.Assert( !mapViewportToSheet.ContainsKey(v.Id), "expected viewport to be contained" + " in only one single sheet"); mapViewportToSheet.Add(v.Id, idSheet); } } return(Result.Cancelled); }
/// <summary> /// List some properties of a given room to the /// Visual Studio debug output window. /// </summary> void ListRoomData(Room room) { SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions(); string nr = room.Number; string name = room.Name; double area = room.Area; Location loc = room.Location; LocationPoint lp = loc as LocationPoint; XYZ p = (null == lp) ? XYZ.Zero : lp.Point; BoundingBoxXYZ bb = room.get_BoundingBox(null); IList <IList <BoundarySegment> > boundary = room.GetBoundarySegments(opt); int nLoops = boundary.Count; int nFirstLoopSegments = 0 < nLoops ? boundary[0].Count : 0; BoundingBoxXYZ boundary_bounding_box = GetBoundingBox(boundary); List <XYZ> convex_hull = GetConvexHullOfRoomBoundary(boundary); List <XYZ> boundary_pts = GetBoundaryPoints( boundary); string room_point_str, lower_left_str, boundary_pts_str, convex_hull_str, bounding_box_str; double llx = boundary_bounding_box.Min.X; if (double.MaxValue == llx) { lower_left_str = "undefined"; Debug.Assert(0 == boundary_pts.Count, "expected empty boundary for undefined lower left corner"); Debug.Assert(0 == convex_hull.Count, "expected empty convex hull for undefined lower left corner"); } else { lower_left_str = _exportInMillimetres ? new IntPoint3d(boundary_bounding_box.Min) .ToString(_exportCsv) : Util.PointString( boundary_bounding_box.Min, _exportCsv); } if (_exportInMillimetres) { room_point_str = new IntPoint3d(p) .ToString(_exportCsv); string separator = _exportCsv ? " " : ", "; boundary_pts_str = string.Join(separator, boundary_pts.Select <XYZ, string>(q => new IntPoint2d(q.X, q.Y) .ToString(_exportCsv))); convex_hull_str = string.Join(separator, convex_hull.Select <XYZ, string>(q => new IntPoint2d(q.X, q.Y) .ToString(_exportCsv))); bounding_box_str = (null == bb) ? "null" : string.Format("{0}{1}{2}", new IntPoint3d(bb.Min) .ToString(_exportCsv), separator, new IntPoint3d(bb.Max) .ToString(_exportCsv)); } else { room_point_str = Util.PointString( p, _exportCsv); IEnumerable <UV> boundary_pts_2d = boundary_pts .Select <XYZ, UV>(q => new UV(q.X, q.Y)); IEnumerable <UV> convex_hull_2d = convex_hull .Select <XYZ, UV>(q => new UV(q.X, q.Y)); boundary_pts_str = Util.PointArrayString( boundary_pts_2d, _exportCsv); convex_hull_str = Util.PointArrayString( convex_hull_2d, _exportCsv); bounding_box_str = (null == bb) ? "null" : Util.BoundingBoxString(bb, _exportCsv); } Debug.Print(string.Format(_format_string, nr, name, room_point_str, lower_left_str, boundary_pts_str, convex_hull_str, bounding_box_str, area, nLoops, Util.PluralSuffix(nLoops), nFirstLoopSegments, Util.PluralSuffix(nFirstLoopSegments))); }
/// <summary> /// List some properties of a given room to the /// Visual Studio debug output window. /// </summary> void ListRoomData(Room room) { SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions(); string nr = room.Number; string name = room.Name; double area = room.Area; Location loc = room.Location; LocationPoint lp = loc as LocationPoint; XYZ p = (null == lp) ? XYZ.Zero : lp.Point; BoundingBoxXYZ bb = room.get_BoundingBox(null); IList <IList <BoundarySegment> > boundary = room.GetBoundarySegments(opt); int nLoops = boundary.Count; int nFirstLoopSegments = 0 < nLoops ? boundary[0].Count : 0; BoundingBoxXYZ boundary_bounding_box = GetBoundingBox(boundary); List <XYZ> convex_hull = GetConvexHullOfRoomBoundary(boundary); List <XYZ> boundary_pts = GetBoundaryPoints( boundary); double llx = boundary_bounding_box.Min.X; string lower_left = Util.PointString(boundary_bounding_box.Min); if (double.MaxValue == llx) { lower_left = "undefined"; Debug.Assert(0 == boundary_pts.Count, "expected empty boundary for undefined lower left corner"); Debug.Assert(0 == convex_hull.Count, "expected empty convex hull for undefined lower left corner"); } IEnumerable <UV> convex_hull_2d = convex_hull .Select <XYZ, UV>(q => new UV(q.X, q.Y)); IEnumerable <UV> boundary_pts_2d = boundary_pts .Select <XYZ, UV>(q => new UV(q.X, q.Y)); Debug.Print(string.Format(_format_string, nr, name, Util.PointString(p), lower_left, Util.PointArrayString(boundary_pts_2d), Util.PointArrayString(convex_hull_2d), Util.BoundingBoxString(bb, true), area, nLoops, Util.PluralSuffix(nLoops), nFirstLoopSegments, Util.PluralSuffix( nFirstLoopSegments))); }