/// <summary> /// 获取Element法向量为normal的所有面 /// </summary> /// <param name="element"></param> /// <param name="normal">normal为空时,返回所有面</param> /// <returns></returns> public static IEnumerable <Face> GetFacesByNormal(Element element, XYZ normal = null) { var solids = GeometryUtils.GetSolids(element); foreach (var solid in solids) { foreach (var face in GetFacesByNormal(solid, normal)) { yield return(face); } } yield break; }
/// <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()); }