using Autodesk.Revit.DB; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GraphicsStudy { public static class WallMethod { /// /// 找到相交的墙 /// /// /// public static List GetGeoInsterEle(this Wall wall) { List elemIdList = new List(); var geo = wall.get_Geometry(new Options()); foreach (GeometryObject geoObject in geo) { Solid geoSolid = geoObject as Solid; foreach (Face geoFace in geoSolid.Faces) { var generatingEleId = wall.GetGeneratingElementIds(geoFace).Where(x => !(elemIdList.Contains(x))).ToList(); generatingEleId.Remove(wall.Id); elemIdList.AddRange(generatingEleId); } } return elemIdList; } /// /// 判断墙是否相连 /// /// /// /// /// public static bool WallIsConnectedWall(this Wall judgeWall, Wall proWall, out List needPoint) { bool result = false; needPoint = new List(); Line judgeLocationLine = ((judgeWall.Location as LocationCurve).Curve as Line).SetZ(); Line proLocationLine = ((proWall.Location as LocationCurve).Curve as Line).SetZ(); //只对平行的处理 if (!judgeLocationLine.Direction.IsParallel(proLocationLine.Direction)) return result; var judgeGeo = judgeWall.get_Geometry(new Options()); Face jugeDownFace = GeoMethod.GetGeoEleDownFace(judgeGeo); var proGeo = proWall.get_Geometry(new Options()); Face proDownFace = GeoMethod.GetGeoEleDownFace(proGeo); List solidList = new List(); //想法一 用布尔运算去测试 //收集几何体 double judgeSolidSurfaceArea = 0; double prosolidSurfaceArea = 0; List judgeSolids = GeoMethod.GetSolids(judgeGeo); List proSolids = GeoMethod.GetSolids(proGeo); foreach (var judgeSolid in judgeSolids) { judgeSolidSurfaceArea += judgeSolid.SurfaceArea; solidList.Add(judgeSolid); } foreach (var proSolid in proSolids) { prosolidSurfaceArea += proSolid.SurfaceArea; solidList.Add(proSolid); } Solid fuseSolid = solidList.SolidBatchBoolean(BooleanOperationsType.Union); if (judgeSolidSurfaceArea + prosolidSurfaceArea - fuseSolid.SurfaceArea > 0) { result = true; //收集中间的两个点 List pointList = new List() { judgeLocationLine.GetEndPoint(0), judgeLocationLine.GetEndPoint(1), proLocationLine.GetEndPoint(0), proLocationLine.GetEndPoint(1) }; pointList = pointList.OrderBy(x => x.DotProduct(judgeLocationLine.Direction).Round(3)).ToList(); needPoint.Add(pointList[1]); needPoint.Add(pointList[2]); } return result; } } }