/// <summary> /// Check wall's two ends in three states /// </summary> /// <param name="wall">The wall to be checked</param> /// <param name="locationCurve">The wall's location curve</param> /// <param name="end">The index indicates the start or end of this wall</param> /// <param name="endnode">Result XML node</param> /// <returns>The check result</returns> private XElement checkWallEnd(Wall wall, LocationCurve locationCurve, int end, XElement endnode) { // Initial state XElement stateNode = new XElement("Initial", new XAttribute("Name", "Initial")); endnode.Add(GetState(wall, locationCurve, end, stateNode)); // Disallow join WallUtils.DisallowWallJoinAtEnd(wall, end); // After DisallowWallJoinAtEnd Evoked state stateNode = new XElement("After_DisallowWallJoinAtEnd_Evoked", new XAttribute("Name", "After_DisallowWallJoinAtEnd_Evoked")); endnode.Add(GetState(wall, locationCurve, end, stateNode)); // Allow join WallUtils.AllowWallJoinAtEnd(wall, end); // After AllowWallJoinAtEnd Evoked state stateNode = new XElement("After_DisallowWallJoinAtEnd_Evoked", new XAttribute("Name", "After_DisallowWallJoinAtEnd_Evoked")); endnode.Add(GetState(wall, locationCurve, end, stateNode)); return(endnode); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; Autodesk.Revit.DB.View target_view = doc.ActiveView; FilteredElementCollector elementInView = new FilteredElementCollector(doc, target_view.Id); ElementCategoryFilter filter_wall = new ElementCategoryFilter(BuiltInCategory.OST_Walls); IList <Element> Walls = elementInView.WherePasses(filter_wall).WhereElementIsNotElementType().ToElements(); using (Transaction trans = new Transaction(doc, "連接牆")) { trans.Start(); foreach (Element ele in Walls) { Wall wall = ele as Wall; //--允許牆接合 WallUtils.AllowWallJoinAtEnd(wall, 0); WallUtils.AllowWallJoinAtEnd(wall, 1); LocationCurve curve = wall.Location as LocationCurve; for (int i = 0; i < 2; i++) { curve.set_JoinType(i, JoinType.Miter); } } trans.Commit(); } MessageBox.Show("連接牆完成"); return(Result.Succeeded); }
protected override void OnBeforeCommit(Document document, string strTransactionName) { base.OnBeforeCommit(document, strTransactionName); // Reenable new joined walls foreach (var wallToJoin in joinedWalls) { WallUtils.AllowWallJoinAtEnd(wallToJoin, 0); WallUtils.AllowWallJoinAtEnd(wallToJoin, 1); } joinedWalls = new List <Wall>(); }
protected override void OnAfterStart(Document document, string strTransactionName) { if (!run) { return; } base.OnAfterStart(document, strTransactionName); // Disable all previous walls joins if (PreviousStructure is object) { var unjoinedWalls = PreviousStructure.OfType <RhinoInside.Revit.GH.Types.Element>(). Select(x => x.Value). OfType <Wall>(). Where(x => x.Pinned). Select ( x => Tuple.Create ( x, (x.Location as LocationCurve).get_JoinType(0), (x.Location as LocationCurve).get_JoinType(1) ) ). ToArray(); foreach (var unjoinedWall in unjoinedWalls) { var location = unjoinedWall.Item1.Location as LocationCurve; if (WallUtils.IsWallJoinAllowedAtEnd(unjoinedWall.Item1, 0)) { WallUtils.DisallowWallJoinAtEnd(unjoinedWall.Item1, 0); WallUtils.AllowWallJoinAtEnd(unjoinedWall.Item1, 0); location.set_JoinType(0, unjoinedWall.Item2); } if (WallUtils.IsWallJoinAllowedAtEnd(unjoinedWall.Item1, 1)) { WallUtils.DisallowWallJoinAtEnd(unjoinedWall.Item1, 1); WallUtils.AllowWallJoinAtEnd(unjoinedWall.Item1, 1); location.set_JoinType(1, unjoinedWall.Item3); } } } }
public override void OnPrepare(IReadOnlyCollection <Document> documents) { if (!run) { return; } base.OnPrepare(documents); // Reenable new joined walls foreach (var wallToJoin in walls) { WallUtils.AllowWallJoinAtEnd(wallToJoin, 0); WallUtils.AllowWallJoinAtEnd(wallToJoin, 1); } walls = new List <Autodesk.Revit.DB.Wall>(); }
public void Restore() { foreach (var w in this.walls) { if (w == null || w.IsValidObject == false) { continue; } var values = this.original[w.Id]; if (values[0]) { WallUtils.AllowWallJoinAtEnd(w, 0); } if (values[1]) { WallUtils.AllowWallJoinAtEnd(w, 1); } } }
public static void SetJoinEnd(Wall _wall, bool[] _joinEnd) { if (_joinEnd[0]) { WallUtils.AllowWallJoinAtEnd(_wall, 0); } else { WallUtils.DisallowWallJoinAtEnd(_wall, 0); } if (_joinEnd[1]) { WallUtils.AllowWallJoinAtEnd(_wall, 1); } else { WallUtils.DisallowWallJoinAtEnd(_wall, 1); } }
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); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication application = commandData.get_Application(); Document document = application.get_ActiveUIDocument().get_Document(); Selection selection = application.get_ActiveUIDocument().get_Selection(); ICollection <ElementId> elementIds = selection.GetElementIds(); List <Element> list = new List <Element>(); foreach (ElementId item in elementIds) { Element element = document.GetElement(item); list.Add(element); } if (list.Count > 0) { GlobolVar.G_JoinWay = "Allow"; WF_StartEnd wF_StartEnd = new WF_StartEnd(); wF_StartEnd.ShowDialog(); if (GlobolVar.G_JoinStatus == -1) { return(0); } Transaction val = new Transaction(document); val.Start("AllowJoin"); foreach (Element item2 in list) { if (item2.get_Category().get_Id().get_IntegerValue() == -2000011) { try { FailureHandlingOptions failureHandlingOptions = val.GetFailureHandlingOptions(); MyFailuresPreProcessor myFailuresPreProcessor = new MyFailuresPreProcessor(); failureHandlingOptions.SetFailuresPreprocessor(myFailuresPreProcessor); val.SetFailureHandlingOptions(failureHandlingOptions); if (GlobolVar.G_JoinStatus == 0) { WallUtils.AllowWallJoinAtEnd(item2 as Wall, 0); WallUtils.AllowWallJoinAtEnd(item2 as Wall, 1); } else if (GlobolVar.G_JoinStatus == 1) { WallUtils.AllowWallJoinAtEnd(item2 as Wall, 0); } else if (GlobolVar.G_JoinStatus == 2) { WallUtils.AllowWallJoinAtEnd(item2 as Wall, 1); } } catch { } } } val.Commit(); } else { TaskDialog.Show("Result", "None Element Selected"); } return(0); }