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); }
/// <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 override void PreProcess() { if (needDisjoinEnds) { WallUtils.DisallowWallJoinAtEnd(this.Wall, 0); WallUtils.DisallowWallJoinAtEnd(this.Wall, 1); } }
public void UnjoinAll() { foreach (var w in this.walls) { WallUtils.DisallowWallJoinAtEnd(w, 0); WallUtils.DisallowWallJoinAtEnd(w, 1); } }
private bool[] getWallJoinEndStates(Wall _wall) { bool b0 = WallUtils.IsWallJoinAllowedAtEnd(_wall, 0); bool b1 = WallUtils.IsWallJoinAllowedAtEnd(_wall, 1); return(new bool[2] { b0, b1 }); }
public WallEndJoinCtrl(List <Wall> _walls) { this.walls = _walls; foreach (var w in _walls) { var j0 = WallUtils.IsWallJoinAllowedAtEnd(w, 0); var j1 = WallUtils.IsWallJoinAllowedAtEnd(w, 1); original[w.Id] = new bool[] { j0, j1 }; } }
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 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 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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Application app = commandData.Application.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; IList<Reference> ref2List = new List<Reference>(); try { ref2List = uidoc.Selection.PickObjects(ObjectType.Element, new WallOrBeamSelectFilter(), "Pick walls and/or beams to disallow join in both ends"); } catch(Autodesk.Revit.Exceptions.OperationCanceledException) { message = "Command cancelled, Click finish in top left corner to complete the command"; return Result.Cancelled; } using (Transaction t1 = new Transaction(doc, "Dissalow Join")) { t1.Start(); foreach (Reference r in ref2List) { Element e = doc.GetElement(r); if (e is Wall) { Wall wall = e as Wall; WallUtils.DisallowWallJoinAtEnd(wall, 0); WallUtils.DisallowWallJoinAtEnd(wall, 1); } else if (e.Category.Id.IntegerValue == (int) BuiltInCategory.OST_StructuralFraming) { FamilyInstance familyInstance = e as FamilyInstance; StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 0); StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 1); } } t1.Commit(); } return Result.Succeeded; }
protected override void OnAfterStart(Document document, string strTransactionName) { base.OnAfterStart(document, strTransactionName); // Disable all previous walls joins if (PreviousStructure != null) { foreach ( var unjoinedWall in PreviousStructure.OfType <Types.Element>(). Select(x => document.GetElement(x)). OfType <Wall>(). Where(x => x.Pinned) ) { WallUtils.DisallowWallJoinAtEnd(unjoinedWall, 0); WallUtils.DisallowWallJoinAtEnd(unjoinedWall, 1); } document.Regenerate(); } }
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); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private static Dictionary <PlanarSurface, List <PlanarSurface> > PanelSurfaces_HostDocument(this HostObject hostObject, IEnumerable <ElementId> insertsToIgnore = null, RevitSettings settings = null) { List <Autodesk.Revit.DB.Plane> planes = hostObject.IPanelPlanes(); if (planes.Count == 0) { return(null); } Document doc = hostObject.Document; Dictionary <PlanarSurface, List <PlanarSurface> > result = new Dictionary <PlanarSurface, List <PlanarSurface> >(); IList <ElementId> inserts = hostObject.FindInserts(true, true, true, true); if (insertsToIgnore != null) { inserts = inserts.Where(x => insertsToIgnore.All(y => x.IntegerValue != y.IntegerValue)).ToList(); } Transaction t = new Transaction(doc); FailureHandlingOptions failureHandlingOptions = t.GetFailureHandlingOptions().SetClearAfterRollback(true); t.Start("Temp Delete Inserts And Unjoin Geometry"); try { foreach (ElementId id in JoinGeometryUtils.GetJoinedElements(doc, hostObject)) { JoinGeometryUtils.UnjoinGeometry(doc, hostObject, doc.GetElement(id)); } if (hostObject is Wall) { WallUtils.DisallowWallJoinAtEnd((Wall)hostObject, 0); WallUtils.DisallowWallJoinAtEnd((Wall)hostObject, 1); } if (insertsToIgnore != null) { doc.Delete(insertsToIgnore.ToList()); } doc.Regenerate(); List <Solid> solidsWithOpenings = hostObject.Solids(new Options()); List <Solid> fullSolids; if (inserts.Count != 0) { solidsWithOpenings = solidsWithOpenings.Select(x => SolidUtils.Clone(x)).ToList(); doc.Delete(inserts); doc.Regenerate(); fullSolids = hostObject.Solids(new Options()); } else { fullSolids = solidsWithOpenings; } fullSolids = fullSolids.SelectMany(x => SolidUtils.SplitVolumes(x)).ToList(); if (hostObject is Wall) { fullSolids.ForEach(x => BooleanOperationsUtils.CutWithHalfSpaceModifyingOriginalSolid(x, planes[0])); Autodesk.Revit.DB.Plane flippedPlane = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-planes[0].Normal, planes[0].Origin + planes[0].Normal * 1e-3); fullSolids.ForEach(x => BooleanOperationsUtils.CutWithHalfSpaceModifyingOriginalSolid(x, flippedPlane)); fullSolids = fullSolids.SelectMany(x => SolidUtils.SplitVolumes(x)).ToList(); planes[0] = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-planes[0].Normal, planes[0].Origin); } foreach (Autodesk.Revit.DB.Plane plane in planes) { foreach (Solid s in fullSolids) { List <CurveLoop> loops = new List <CurveLoop>(); foreach (Autodesk.Revit.DB.Face f in s.Faces) { PlanarFace pf = f as PlanarFace; if (pf == null) { continue; } if (Math.Abs(1 - pf.FaceNormal.DotProduct(plane.Normal)) <= settings.DistanceTolerance && Math.Abs((pf.Origin - plane.Origin).DotProduct(plane.Normal)) <= settings.AngleTolerance) { loops.AddRange(pf.GetEdgesAsCurveLoops()); } } CurveLoop outline = loops.FirstOrDefault(x => x.IsCounterclockwise(plane.Normal)); PlanarSurface surface = new PlanarSurface(outline.FromRevit(), null); List <PlanarSurface> openings = new List <PlanarSurface>(); foreach (CurveLoop loop in loops.Where(x => x != outline)) { openings.Add(new PlanarSurface(loop.FromRevit(), null)); } if (inserts.Count != 0) { List <Solid> openingVolumes = new List <Solid>(); foreach (Solid s2 in solidsWithOpenings) { openingVolumes.Add(BooleanOperationsUtils.ExecuteBooleanOperation(s, s2, BooleanOperationsType.Difference)); } foreach (Solid s2 in openingVolumes) { foreach (Autodesk.Revit.DB.Face f in s2.Faces) { PlanarFace pf = f as PlanarFace; if (pf == null) { continue; } if (Math.Abs(1 - pf.FaceNormal.DotProduct(plane.Normal)) <= settings.DistanceTolerance && Math.Abs((pf.Origin - plane.Origin).DotProduct(plane.Normal)) <= settings.AngleTolerance) { foreach (CurveLoop cl in pf.GetEdgesAsCurveLoops()) { openings.Add(new PlanarSurface(cl.FromRevit(), null)); } } } } } result.Add(surface, openings); } } } catch { BH.Engine.Reflection.Compute.RecordError(String.Format("Geometrical processing of a Revit element failed due to an internal Revit error. Converted panel might be missing one or more of its surfaces. Revit ElementId: {0}", hostObject.Id)); } t.RollBack(failureHandlingOptions); return(result); }
/// <summary> /// Get wall's one end IsWallJoinAllowedAtEnd API method's result /// </summary> /// <param name="wall">The wall to be checked</param> /// <param name="end">The index indicates the start or end of this wall</param> /// <returns>The check result</returns> private XElement GetIsWallJoinAllowedAtEnd(Wall wall, int end) { return(new XElement("IsWallJoinAllowedAtEnd", new XAttribute("Value", WallUtils.IsWallJoinAllowedAtEnd(wall, end)))); }
// inputs: n=shape List <List <Wall> > Create_House_Shapes(Document doc, string n, bool a, bool b, bool c, bool d, double _heigth_) { //list walls output List <Wall> output_wall_Rigth = new List <Wall>(); List <Wall> output_wall_Left = new List <Wall>(); List <List <Wall> > output = new List <List <Wall> >(); //inputs //level Level level = GetLevel(doc, "Nivel 1"); // coord XYZ(x,y,z) XYZ stPoint = new XYZ(0, 0, 0); //Door & windows bool door_RightWall = a; bool wind_RigthWall = b; bool door_LeftWall = c; bool wind_LeftWall = d; Transaction trans = new Transaction(doc); trans.Start("Create House"); if (n == "square") { #region square //TaskDialog.Show("ALERTA", "--------------------------------------------------------------------------"); double heigth_double = _heigth_; // Crear Wall Primer XYZ endPoint = new XYZ(30, 0, 0); XYZ endPoint_2 = new XYZ(30, 30, 0); XYZ endPoint_3 = new XYZ(0, 30, 0); Line newLineN = Line.CreateBound(stPoint, endPoint); Line newLineN_2 = Line.CreateBound(endPoint, endPoint_2); Line newLineN_3 = Line.CreateBound(endPoint_2, endPoint_3); Line newLineN_4 = Line.CreateBound(endPoint_3, stPoint); Wall wall = Wall.Create(doc, newLineN, level.Id, false); Wall wall_2 = Wall.Create(doc, newLineN_2, level.Id, false); Wall wall_3 = Wall.Create(doc, newLineN_3, level.Id, false); Wall wall_4 = Wall.Create(doc, newLineN_4, level.Id, false); List <Wall> lista_walls = new List <Wall>(); lista_walls.Add(wall); lista_walls.Add(wall_2); lista_walls.Add(wall_3); lista_walls.Add(wall_4); output_wall_Rigth.Add(wall_2); output_wall_Rigth.Add(wall_4); output_wall_Left.Add(wall); output_wall_Left.Add(wall_3); output.Add(output_wall_Rigth); output.Add(output_wall_Left); foreach (Wall e in lista_walls) { Parameter height = e.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM); if (!height.IsReadOnly) { height.Set(heigth_double); } if (WallUtils.IsWallJoinAllowedAtEnd(e, 1)) { WallUtils.DisallowWallJoinAtEnd(e, 1); } if (WallUtils.IsWallJoinAllowedAtEnd(e, 0)) { WallUtils.DisallowWallJoinAtEnd(e, 0); } } #endregion } else if (n == "rectangle") { #region rectangle double heigth_double = _heigth_; // Crear Wall Primer XYZ endPoint = new XYZ(20, 0, 0); XYZ endPoint_2 = new XYZ(20, 10, 0); XYZ endPoint_3 = new XYZ(0, 10, 0); Line newLineN = Line.CreateBound(stPoint, endPoint); Line newLineN_2 = Line.CreateBound(endPoint, endPoint_2); Line newLineN_3 = Line.CreateBound(endPoint_2, endPoint_3); Line newLineN_4 = Line.CreateBound(endPoint_3, stPoint); Wall wall = Wall.Create(doc, newLineN, level.Id, false); Wall wall_2 = Wall.Create(doc, newLineN_2, level.Id, false); Wall wall_3 = Wall.Create(doc, newLineN_3, level.Id, false); Wall wall_4 = Wall.Create(doc, newLineN_4, level.Id, false); List <Wall> lista_walls = new List <Wall>(); lista_walls.Add(wall); lista_walls.Add(wall_2); lista_walls.Add(wall_3); lista_walls.Add(wall_4); output_wall_Rigth.Add(wall_2); output_wall_Rigth.Add(wall_4); output_wall_Left.Add(wall); output_wall_Left.Add(wall_3); output.Add(output_wall_Rigth); output.Add(output_wall_Left); foreach (Wall e in lista_walls) { Parameter height = e.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM); if (!height.IsReadOnly) { height.Set(heigth_double); } if (WallUtils.IsWallJoinAllowedAtEnd(e, 1)) { WallUtils.DisallowWallJoinAtEnd(e, 1); } if (WallUtils.IsWallJoinAllowedAtEnd(e, 0)) { WallUtils.DisallowWallJoinAtEnd(e, 0); } } #endregion } else if (n == "triangle") { #region triangle double heigth_double = _heigth_; // Crear Wall Primer XYZ endPoint = new XYZ(20, 0, 0); XYZ endPoint_2 = new XYZ(10, 10 * 1.7320508075, 0); Line newLineN = Line.CreateBound(stPoint, endPoint); Line newLineN_2 = Line.CreateBound(endPoint, endPoint_2); Line newLineN_3 = Line.CreateBound(endPoint_2, stPoint); Wall wall = Wall.Create(doc, newLineN, level.Id, false); Wall wall_2 = Wall.Create(doc, newLineN_2, level.Id, false); Wall wall_3 = Wall.Create(doc, newLineN_3, level.Id, false); List <Wall> lista_walls = new List <Wall>(); lista_walls.Add(wall); lista_walls.Add(wall_2); lista_walls.Add(wall_3); output_wall_Rigth.Add(wall); output_wall_Rigth.Add(wall_2); output_wall_Rigth.Add(wall_3); output.Add(output_wall_Rigth); foreach (Wall e in lista_walls) { Parameter height = e.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM); if (!height.IsReadOnly) { height.Set(heigth_double); } if (WallUtils.IsWallJoinAllowedAtEnd(e, 1)) { WallUtils.DisallowWallJoinAtEnd(e, 1); } if (WallUtils.IsWallJoinAllowedAtEnd(e, 0)) { WallUtils.DisallowWallJoinAtEnd(e, 0); } } #endregion } trans.Commit(); return(output); }
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 string Draw_By_Revit(UIApplication uiapp, Document doc) { string result = "F"; try { level_data item_level_bottom = (level_data)level_bottom.SelectedItem; level_data item_level_top = (level_data)level_top.SelectedItem; family_data item_family = (family_data)family.SelectedItem; type_data item_type = (type_data)type.SelectedItem; Draw_Data(item_type, item_family, doc); Level level_element_bottom = item_level_bottom.level; Level level_element_top = item_level_top.level; double elevation_bottom_value = Convert.ToDouble(elevation_bottom.Text) / myAll_Data.list_unit_value_data[2] - item_level_bottom.elevation; double elevation_top_value = Convert.ToDouble(elevation_top.Text) / myAll_Data.list_unit_value_data[2] - item_level_top.elevation; if (new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(x => x.Name == item_type.type.Name).ToList().Count() > 0) { FamilyInstance instance = null; FamilySymbol familySymbol = item_type.type as FamilySymbol; if (familySymbol.IsActive == false) { familySymbol.Activate(); } if (item_type.type.Category.Name == myAll_Data.list_category_draw[4]) { instance = doc.Create.NewFamilyInstance(my_draw_data.center, familySymbol, level_element_bottom, StructuralType.Column) as FamilyInstance; instance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).Set(elevation_bottom_value); instance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).Set(level_element_top.Id); instance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).Set(elevation_top_value); } else if (item_type.type.Category.Name == myAll_Data.list_category_draw[5]) { instance = doc.Create.NewFamilyInstance(my_draw_data.curve, familySymbol, level_element_top, StructuralType.Beam) as FamilyInstance; instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).Set(0.1); instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).Set(0.1); instance.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).Set(level_element_top.Id); instance.get_Parameter(BuiltInParameter.Z_OFFSET_VALUE).Set(elevation_top_value); instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).Set(0); instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).Set(0); StructuralFramingUtils.DisallowJoinAtEnd(instance, 0); StructuralFramingUtils.DisallowJoinAtEnd(instance, 1); } else { instance = doc.Create.NewFamilyInstance(my_draw_data.center, familySymbol, host_of_opening, level_element_bottom, StructuralType.NonStructural); if (instance.Host != null) { if (host_of_opening.Category.Name == myAll_Data.list_category_draw_host[0]) { instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level_element_top.Id); } else if (host_of_opening.Category.Name == myAll_Data.list_category_draw_host[1]) { instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); if (instance.LookupParameter(myAll_Data.list_parameter_tag[4]) != null) { instance.LookupParameter(myAll_Data.list_parameter_tag[4]).Set(Convert.ToDouble(elevation_bottom.Text) / myAll_Data.list_unit_value_data[2]); } if (instance.LookupParameter(myAll_Data.list_parameter_tag[0]) != null) { instance.LookupParameter(myAll_Data.list_parameter_tag[0]).Set(0); } } else { if (instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM) != null && instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsElementId().IntegerValue != -1 && instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).IsReadOnly == false) { instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); } else if (instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM) != null && instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsElementId().IntegerValue != -1 && instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).IsReadOnly == false) { instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); } } } else { if (instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM) != null && instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsElementId().IntegerValue != -1 && instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).IsReadOnly == false) { instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); } else if (instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM) != null && instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsElementId().IntegerValue != -1 && instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).IsReadOnly == false) { instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value); } } } if (my_draw_data.point1 != null) { Move_Element(my_draw_data.point1, my_draw_data.point2, doc, instance, item_type, item_family); } foreach (parameter_data data in my_parameter_data) { if (instance.LookupParameter(data.parameter_name).IsReadOnly == false) { if (data.parameter_value == "True") { instance.LookupParameter(data.parameter_name).Set(1); } else if (data.parameter_value == "False") { instance.LookupParameter(data.parameter_name).Set(0); } else { instance.LookupParameter(data.parameter_name).Set(Convert.ToDouble(data.parameter_value) / myAll_Data.list_unit_value_data[2]); } } } if (host_of_opening == null) { Join_Element(doc, instance); } } else { WallType wallType = item_type.type as WallType; Wall instance = Wall.Create(doc, my_draw_data.curve, wallType.Id, level_element_bottom.Id, 10, 0, true, true); instance.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).Set(level_element_bottom.Id); instance.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).Set(elevation_bottom_value); instance.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(level_element_top.Id); instance.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).Set(elevation_top_value); WallUtils.DisallowWallJoinAtEnd(instance, 0); WallUtils.DisallowWallJoinAtEnd(instance, 1); instance.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM).Set(0); if (my_draw_data.point1 != null) { Move_Element(my_draw_data.point1, my_draw_data.point2, doc, instance, item_type, item_family); } Join_Element(doc, instance); } result = "S"; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }