/// <summary> /// Get wall's one end all joined walls /// </summary> /// <param name="locationCurve">The wall's location curve</param> /// <param name="end">The index indicates the start or end of this wall</param> /// <returns>The check result</returns> private XElement GetJoinedWalls(LocationCurve locationCurve, int end) { // retrieve joined elements ElementArray array = locationCurve.get_ElementsAtJoin(end); XElement joinedwallsNode = new XElement("JoinedWalls", new XAttribute("Count", array.Size.ToString())); // output array foreach (Element ele in array) { if (ele is Wall) { joinedwallsNode.Add(new XElement("JoinedWall", new XAttribute("Name", ele.Name))); } } return(joinedwallsNode); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = app.ActiveUIDocument.Document; List <Element> walls = new List <Element>(); if (!Util.GetSelectedElementsOrAll( walls, uidoc, typeof(Wall))) { Selection sel = uidoc.Selection; message = (0 < sel.GetElementIds().Count) ? "Please select some wall elements." : "No wall elements found."; return(Result.Failed); } int i, n; string desc, s = null; //List<Element> neighbours; ElementArray neighbours; foreach (Wall wall in walls) { desc = Util.ElementDescription(wall); LocationCurve c = wall.Location as LocationCurve; if (null == c) { s = desc + ": No wall curve found."; } else { s = string.Empty; for (i = 0; i < 2; ++i) { neighbours = c.get_ElementsAtJoin(i); n = neighbours.Size; s += string.Format( "\n\n{0} {1} point has {2} neighbour{3}{4}", desc, (0 == i ? "start" : "end"), n, Util.PluralSuffix(n), Util.DotOrColon(n)); foreach (Wall nb in neighbours) { s += "\n " + Util.ElementDescription(nb); } } } Util.InfoMsg(s); } return(Result.Failed); }
/// <summary> /// Get wall's one end all joined walls /// </summary> /// <param name="locationCurve">The wall's location curve</param> /// <param name="end">The index indicates the start or end of this wall</param> /// <returns>The check result</returns> private XElement GetJoinedWalls(LocationCurve locationCurve, int end) { // retrieve joined elements ElementArray array = locationCurve.get_ElementsAtJoin(end); XElement joinedwallsNode = new XElement("JoinedWalls", new XAttribute("Count", array.Size.ToString())); // output array foreach (Element ele in array) { if (ele is Wall) { joinedwallsNode.Add(new XElement("JoinedWall", new XAttribute("Name", ele.Name))); } } return joinedwallsNode; }
public static List <Autodesk.Revit.DB.Wall> TrimOrExtendWall(this IEnumerable <Autodesk.Revit.DB.Wall> walls, double maxDistance, double tolerance = Core.Tolerance.Distance) { Dictionary <double, Dictionary <Autodesk.Revit.DB.Wall, Segment2D> > dictionary = new Dictionary <double, Dictionary <Autodesk.Revit.DB.Wall, Segment2D> >(); foreach (Autodesk.Revit.DB.Wall wall in walls) { Curve curve = (wall.Location as LocationCurve).Curve; Segment3D segment3D = Geometry.Revit.Convert.ToSAM_Segment3D(curve); double elevation = Math.Min(segment3D[0].Z, segment3D[1].Z); Dictionary <Autodesk.Revit.DB.Wall, Segment2D> dictionary_Wall = null; if (!dictionary.TryGetValue(elevation, out dictionary_Wall)) { dictionary_Wall = new Dictionary <Autodesk.Revit.DB.Wall, Segment2D>(); dictionary[elevation] = dictionary_Wall; } dictionary_Wall[wall] = Geometry.Spatial.Plane.WorldXY.Convert(segment3D); } List <Autodesk.Revit.DB.Wall> result = new List <Autodesk.Revit.DB.Wall>(); foreach (KeyValuePair <double, Dictionary <Autodesk.Revit.DB.Wall, Segment2D> > keyValuePair in dictionary) { List <Segment2D> segment2Ds = keyValuePair.Value.Values.ToList(); //Filtering Walls by Level List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> > tupleList = new List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> >(); foreach (KeyValuePair <Autodesk.Revit.DB.Wall, Segment2D> keyValuePair_Wall in keyValuePair.Value) { LocationCurve locationCurve = keyValuePair_Wall.Key.Location as LocationCurve; List <int> indexes = new List <int>(); ElementArray elementArray = null; elementArray = locationCurve.get_ElementsAtJoin(0); if (elementArray == null || elementArray.Size == 0) { indexes.Add(0); } elementArray = locationCurve.get_ElementsAtJoin(1); if (elementArray == null || elementArray.Size == 0) { indexes.Add(1); } //if (indexes.Count > 0) tupleList.Add(new Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool>(keyValuePair_Wall.Key, keyValuePair_Wall.Value, indexes, false)); } //Seeking for walls to be extended/trimmed bool updated = true; while (updated) { updated = false; List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> > tupleList_Unconnected = tupleList.FindAll(x => x.Item3 != null && x.Item3.Count > 0); for (int i = 0; i < tupleList_Unconnected.Count; i++) { Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> tuple = tupleList_Unconnected[i]; List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> > tupleList_Temp = new List <Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> >(tupleList); tupleList_Temp.Remove(tuple); Segment2D segment2D = tuple.Item2; List <Tuple <Point2D, Segment2D> > tupleList_Intersection = new List <Tuple <Point2D, Segment2D> >(); foreach (Segment2D segment2D_Temp in tupleList_Temp.ConvertAll(x => x.Item2)) { Point2D point2D_Intersection = segment2D_Temp.Intersection(segment2D, false, tolerance); if (point2D_Intersection == null) { //Checking Colinear Segment2Ds if can be extended Vector2D direction_Temp = segment2D_Temp.Direction; Vector2D direction = segment2D.Direction; if (!direction_Temp.AlmostEqual(direction, tolerance) && !direction_Temp.AlmostEqual(direction.GetNegated(), tolerance)) { continue; } Point2D point2D_Temp = null; Point2D point2D = null; if (!Geometry.Planar.Query.Closest(segment2D_Temp, segment2D, out point2D_Temp, out point2D, tolerance)) { continue; } if (point2D_Temp.AlmostEquals(point2D, tolerance)) { continue; } Vector2D direction_New = new Vector2D(point2D, point2D_Temp).Unit; if (!direction_Temp.AlmostEqual(direction_New, tolerance) && !direction_Temp.AlmostEqual(direction_New.GetNegated(), tolerance)) { continue; } point2D_Intersection = point2D; } double distance; distance = segment2D.Distance(point2D_Intersection); if (distance > maxDistance) { continue; } distance = segment2D_Temp.Distance(point2D_Intersection); if (distance > maxDistance) { continue; } tupleList_Intersection.Add(new Tuple <Point2D, Segment2D>(point2D_Intersection, segment2D_Temp)); } if (tupleList_Intersection.Count == 0) { continue; } foreach (int index in tuple.Item3) { Point2D point2D = segment2D[index]; tupleList_Intersection.Sort((x, y) => x.Item1.Distance(point2D).CompareTo(y.Item1.Distance(point2D))); Tuple <Point2D, Segment2D> tuple_Intersection = tupleList_Intersection.Find(x => x.Item1.Distance(point2D) < maxDistance); if (tuple_Intersection == null) { continue; } Segment2D segment2D_Intersection = tuple_Intersection.Item2; int j = tupleList.FindIndex(x => x.Item2 == segment2D_Intersection); if (j == -1) { continue; } int k = tupleList.FindIndex(x => x.Item2 == segment2D); if (k == -1) { continue; } //TODO: Double Check if works (added 2020.05.14) if ((index == 0 && segment2D[1].AlmostEquals(tuple_Intersection.Item1)) || (index == 1 && segment2D[0].AlmostEquals(tuple_Intersection.Item1))) { tupleList[k] = new Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool>(tuple.Item1, new Segment2D(tuple_Intersection.Item1, tuple_Intersection.Item1), tuple.Item3.FindAll(x => x != index), true); updated = true; break; } Segment2D segment2D_Temp; if (segment2D_Intersection[0].Distance(tuple_Intersection.Item1) < maxDistance || segment2D_Intersection[1].Distance(tuple_Intersection.Item1) < maxDistance) { segment2D_Temp = new Segment2D(segment2D_Intersection); segment2D_Temp.Adjust(tuple_Intersection.Item1); if (!segment2D_Temp.AlmostSimilar(segment2D_Intersection) && segment2D_Temp.GetLength() > segment2D_Intersection.GetLength()) { tupleList[j] = new Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool>(tupleList[j].Item1, segment2D_Temp, tupleList[j].Item3.FindAll(x => x != segment2D_Temp.GetEndIndex(tuple_Intersection.Item1)), true); } } segment2D_Temp = new Segment2D(segment2D); segment2D_Temp.Adjust(tuple_Intersection.Item1); if (segment2D_Temp.AlmostSimilar(segment2D)) { continue; } tupleList[k] = new Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool>(tuple.Item1, segment2D_Temp, tuple.Item3.FindAll(x => x != index), true); updated = true; break; } if (updated) { break; } } } tupleList.RemoveAll(x => !x.Item4); //Updating Revit Walls foreach (Tuple <Autodesk.Revit.DB.Wall, Segment2D, List <int>, bool> tuple in tupleList) { Autodesk.Revit.DB.Wall wall = tuple.Item1; if (!wall.IsValidObject) { continue; } Segment2D segment2D = tuple.Item2; if (segment2D.GetLength() < tolerance) { wall.Document.Delete(wall.Id); continue; } LocationCurve locationCurve = wall.Location as LocationCurve; JoinType[] joinTypes = new JoinType[] { locationCurve.get_JoinType(0), locationCurve.get_JoinType(1) }; WallUtils.DisallowWallJoinAtEnd(wall, 0); WallUtils.DisallowWallJoinAtEnd(wall, 1); Segment3D segment3D = new Segment3D(new Point3D(segment2D[0].X, segment2D[0].Y, keyValuePair.Key), new Point3D(segment2D[1].X, segment2D[1].Y, keyValuePair.Key)); Line line = Geometry.Revit.Convert.ToRevit(segment3D); locationCurve.Curve = line; WallUtils.AllowWallJoinAtEnd(wall, 0); locationCurve.set_JoinType(0, joinTypes[0]); WallUtils.AllowWallJoinAtEnd(wall, 1); locationCurve.set_JoinType(1, joinTypes[1]); result.Add(tuple.Item1); } } return(result); }
/// <summary> /// Get the Insulation Layer of Right hand joined Walls /// </summary> public Tuple<Curve, Curve> handleJoinsRight(Document doc, LocationCurve wallLocCurve, Curve lower, Curve upper, ref List<int> bannedWalls) { Tuple<Curve, Curve> existing = new Tuple<Curve, Curve>(upper, lower); if (lower.GetType() == typeof(Arc) || lower.GetType() == typeof(NurbSpline)) return existing; if (upper.GetType() == typeof(Arc) || upper.GetType() == typeof(NurbSpline)) return existing; XYZ IntersectionPointLower = null; XYZ IntersectionPointUpper = null; ElementArray elems = wallLocCurve.get_ElementsAtJoin(1); if (elems == null || elems.Size == 0) return existing; foreach (Element elem in elems) { if (elem.GetType() == typeof(Wall)) { Wall wnext = (Wall)elem; if (!bannedWalls.Contains(wnext.Id.IntegerValue)) { Tuple<Curve, Curve> curves = getInsulationLayer(doc, wnext); Curve lowerunbound = lower.Clone(); lowerunbound.MakeUnbound(); Curve upperunbound = upper.Clone(); upperunbound.MakeUnbound(); Curve lowernext = curves.Item2.Clone(); lowernext.MakeUnbound(); IntersectionResultArray result = new IntersectionResultArray(); lowerunbound.Intersect(lowernext, out result); if (result != null && result.Size == 1) { IntersectionPointLower = result.get_Item(0).XYZPoint; } upperunbound.Intersect(lowernext, out result); if (result != null && result.Size == 1) { IntersectionPointUpper = result.get_Item(0).XYZPoint; } } } } if (IntersectionPointLower == null || IntersectionPointUpper == null) return existing; return new Tuple<Curve, Curve>(Line.CreateBound(upper.GetEndPoint(0), IntersectionPointUpper), Line.CreateBound(lower.GetEndPoint(0), IntersectionPointLower)); }
/// <summary> /// Get the Insulation Layer of Left hand joined Walls /// </summary> public Curve handleJoinsLeft(Document doc, LocationCurve wallLocCurve, Curve lower, ref List<int> bannedWalls) { if (lower.GetType() == typeof(Arc) || lower.GetType() == typeof(NurbSpline)) return lower; XYZ IntersectionPoint = null; ElementArray elems = wallLocCurve.get_ElementsAtJoin(0); if (elems == null || elems.Size == 0) return lower; foreach (Element elem in elems) { if (elem.GetType() == typeof(Wall)) { Wall wnext = (Wall)elem; if (!bannedWalls.Contains(wnext.Id.IntegerValue)) { Tuple<Curve, Curve> curves = getInsulationLayer(doc, wnext); Curve lowerunbound = lower.Clone(); lowerunbound.MakeUnbound(); Curve upper = curves.Item1.Clone(); upper.MakeUnbound(); IntersectionResultArray result = new IntersectionResultArray(); lowerunbound.Intersect(upper, out result); if (result != null && result.Size == 1) { IntersectionPoint = result.get_Item(0).XYZPoint; } } } } if (IntersectionPoint == null) return lower; Line l = Line.CreateBound(IntersectionPoint, lower.GetEndPoint(1)); return l; }