private Outline GetBoundingBox(Area area, out CurveArrArray profiles) { profiles = new CurveArrArray(); var minXYZ = new XYZ(0, 0, 0); var maxXYZ = new XYZ(0, 0, 0); var outline = new Outline(minXYZ, maxXYZ); try { if (area.GetBoundarySegments(new SpatialElementBoundaryOptions()) != null) { double maxLength = 0; foreach (var boundarySegments in area.GetBoundarySegments(new SpatialElementBoundaryOptions())) { if (boundarySegments.Count > 0) { var profile = new CurveArray(); double length = 0; foreach (var boundarySegment in boundarySegments) { #if RELEASE2015 var curve = boundarySegment.Curve; #else var curve = boundarySegment.GetCurve(); #endif profile.Append(curve); length += curve.Length; } if (length > maxLength) { maxLength = length; profiles.Insert(profile, 0); //first curve array will be the out most profile. } else { profiles.Append(profile); } } } } double minX = 0; double minY = 0; double minZ = 0; double maxX = 0; double maxY = 0; double maxZ = 0; var first = true; if (profiles.Size > 0) { foreach (CurveArray curveArray in profiles) { foreach (Curve curve in curveArray) { var point = curve.GetEndPoint(0); if (first) { minX = point.X; minY = point.Y; minZ = point.Z; maxX = point.X; maxY = point.Y; maxZ = minZ + 50; first = false; } else { if (point.X < minX) { minX = point.X; } if (point.Y < minY) { minY = point.Y; } if (point.X > maxX) { maxX = point.X; } if (point.Y > maxY) { maxY = point.Y; } } } } } minXYZ = new XYZ(minX, minY, minZ); maxXYZ = new XYZ(maxX, maxY, maxZ); outline = new Outline(minXYZ, maxXYZ); } catch (Exception ex) { MessageBox.Show("Failed to get profiles.\n" + ex.Message, "Get Area Profiles", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(outline); }