Purpose: To connect all unconnected walls together to meet drawing requirements. At first adopted depth traversal method found error: stack overflow, reason is too many loop layers. Later optimized traversal method using breadth traversal, problem solved. Below paste two ways to get walls and connect
Element.GetgeneratingElementIds This method can get connected walls, but haven’t experimented yet.
/* * Connect walls in normal way */ voidUnionWall(Wall wall, List<Wall> walls) { try { var e = BIMTools.Geometry.GetFace(wall, BIMTools.Geometry.FaceNormal.Bottom); var loops = e.GetEdgesAsCurveLoops(); var para = wall.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED); var vPara = wall.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED); var area = para.AsDouble(); var volume = vPara.AsDouble(); Solid ss = BIMTools.Geometry.GetSolid(wall); var height = volume / area; var solid = CreateNewSolid(loops.ToList(), 10, 2950 / 304.8); //Solid after offset List<Wall> nWalls = new List<Wall>(); nWalls.AddRange(walls); var bWall = nWalls.Remove(walls.FirstOrDefault(x => x.Id == wall.Id)); if (nWalls.Count > 1 && bWall) { foreach (var w in nWalls) { var s = BIMTools.Geometry.GetSolid(w); if (s != null && solid != null) { Solid intersect = BooleanOperationsUtils.ExecuteBooleanOperation(solid, s, BooleanOperationsType.Intersect); if (intersect.Volume > 0.0001) { try { if (!JoinGeometryUtils.AreElementsJoined(_document, wall, w)) { JoinGeometryUtils.JoinGeometry(_document, wall, w); wIds.Add(w.Id); } else { wIds.Add(w.Id); }
wIds.Add(w.Id); } catch (ArgumentException) {
}
}
}
}
}
} catch (Exception) { // ignored } }
Traverse way to get walls, here referred to linked list method. Using this method not only can get wall connection but also perform more operations according to corresponding relationship
publicvoidDeleteNode(BFS bfs) { if(_next.Count==0) thrownew ArgumentException($"paramater:_next is null"); var b = _next.FirstOrDefault(x => x._wall.Id.Equals(bfs._wall.Id)); _next.Remove(b); }
public List<BFS> GetNextNode() => _next;
}
public List<BFS> GetInsertWalls(Wall wall,List<Wall> walls) { if(wall==null) thrownew ArgumentNullException($"paramater:wall is null"); if (walls.Count==0) thrownew ArgumentNullException($"paramater:walls is null"); var f = BIMTools.Geometry.GetFace(wall, Geometry.FaceNormal.Bottom); var loops = f.GetEdgesAsCurveLoops(); var solid = CreateNewSolid(loops.ToList(), 10, 3000 / 304.8); List<BFS> intersectWalls = new List<BFS>(); foreach (var wall1 in walls) { if(wall1.Id.Equals(wall.Id)) continue; var s = BIMTools.Geometry.GetSolid(wall1); if (solid != null && s != null) { Solid intersect = BooleanOperationsUtils.ExecuteBooleanOperation(solid, s, BooleanOperationsType.Intersect); if (intersect.Volume > 0.0001) { BFS bfs = new BFS(wall1); intersectWalls.Add(bfs); } } }