/// <summary> /// 获得element的BoundingBoxXYZ /// </summary> /// <param name="element"></param> /// <returns></returns> public static BoundingBoxXYZ GetBoundingBox(this Element element) { if (null == element) { return(null); } // 获取实例的BoundingBox if (element is FamilyInstance) { var bBox = new BoundingBoxXYZ() { Enabled = false }; var solids = GeometryUtils.GetSolids(element); foreach (var solid in solids) { if (solid.Faces.Size <= 0 || solid.Volume <= 1e-6) { continue; } foreach (Edge e in solid.Edges) { var crv = e.AsCurve(); bBox.ExpandToContain(crv.GetEndPoint(0)); bBox.ExpandToContain(crv.GetEndPoint(1)); } } return(bBox); } // 获取一般的BoundingBox Options ops = new Options() { ComputeReferences = true, DetailLevel = ViewDetailLevel.Fine }; GeometryElement geoElem = element.get_Geometry(ops); return(geoElem?.GetBoundingBox()); }
/// <summary> /// 获得能包围所有包围盒的BoundingBox /// </summary> /// <param name="bBoxs"></param> /// <returns></returns> public static BoundingBoxXYZ GetElementsMaxBounding(List <BoundingBoxXYZ> bBoxs) { BoundingBoxXYZ retBBox = new BoundingBoxXYZ() { Enabled = false }; bBoxs.ForEach(bbox => retBBox.ExpandToContain(bbox)); return(retBBox); }
/// <summary> /// Return a bounding box around all the /// walls in the entire model; for just a /// building, or several buildings, this is /// obviously equal to the model extents. /// </summary> static BoundingBoxXYZ GetBoundingBoxAroundAllWalls( Document doc, View view = null) { // Default constructor creates cube from -100 to 100; // maybe too big, but who cares? BoundingBoxXYZ bb = new BoundingBoxXYZ(); FilteredElementCollector walls = new FilteredElementCollector(doc) .OfClass(typeof(Wall)); foreach (Wall wall in walls) { bb.ExpandToContain( wall.get_BoundingBox( view)); } return(bb); }
/// <summary> /// Return bounding box calculated from the room /// boundary segments. The lower left corner turns /// out to be identical with the one returned by /// the standard room bounding box. /// </summary> static BoundingBoxXYZ GetBoundingBox( IList <IList <BoundarySegment> > boundary) { BoundingBoxXYZ bb = new BoundingBoxXYZ(); bb.Clear(); foreach (IList <BoundarySegment> loop in boundary) { foreach (BoundarySegment seg in loop) { Curve c = seg.GetCurve(); IList <XYZ> pts = c.Tessellate(); foreach (XYZ p in pts) { bb.ExpandToContain(p); } } } return(bb); }
public static BoundingBoxXYZ GetBoundingBox(IList <IList <BoundarySegment> > boundary) { BoundingBoxXYZ bb = new BoundingBoxXYZ(); double infinity = double.MaxValue; bb.Min = new XYZ(infinity, infinity, infinity); bb.Max = -bb.Min; foreach (IList <BoundarySegment> loop in boundary) { foreach (BoundarySegment seg in loop) { Curve c = seg.GetCurve(); IList <XYZ> pts = c.Tessellate(); foreach (XYZ p in pts) { bb.ExpandToContain(p); } } } return(bb); }
/// <summary> /// Expand the given bounding box to include /// and contain the given other one. /// </summary> public static void ExpandToContain(this BoundingBoxXYZ bb, BoundingBoxXYZ other) { bb.ExpandToContain(other.Min); bb.ExpandToContain(other.Max); }
/// <summary> /// Return bounding box calculated from the room /// boundary segments. The lower left corner turns /// out to be identical with the one returned by /// the standard room bounding box. /// </summary> static BoundingBoxXYZ GetBoundingBox( IList<IList<BoundarySegment>> boundary) { BoundingBoxXYZ bb = new BoundingBoxXYZ(); double infinity = double.MaxValue; bb.Min = new XYZ( infinity, infinity, infinity ); bb.Max = -bb.Min; foreach( IList<BoundarySegment> loop in boundary ) { foreach( BoundarySegment seg in loop ) { Curve c = seg.GetCurve(); IList<XYZ> pts = c.Tessellate(); foreach( XYZ p in pts ) { bb.ExpandToContain( p ); } } } return bb; }