public void CanUnjoinTwoElements() { var wall1 = ElementSelector.ByElementId(184176, true); var wall2 = ElementSelector.ByElementId(207960, true); var floor = ElementSelector.ByElementId(208259, true); var doc = DocumentManager.Instance.CurrentDBDocument; string expectedNotJoinedExceptionMessages = Revit.Properties.Resources.NotJoinedElements; // Are joined bool originalWall1AndWall2JoinedValue = JoinGeometryUtils.AreElementsJoined(doc, wall1.InternalElement, wall2.InternalElement); Assert.AreEqual(true, originalWall1AndWall2JoinedValue); // Are not joined bool originalWall2AndFloorJoinedValue = JoinGeometryUtils.AreElementsJoined(doc, wall2.InternalElement, floor.InternalElement); Assert.AreEqual(false, originalWall2AndFloorJoinedValue); wall1.UnjoinGeometry(wall2); bool newWall1AndWall2JoinedValue = wall1.AreJoined(wall2); // Are joined should have changed Assert.AreNotEqual(newWall1AndWall2JoinedValue, originalWall1AndWall2JoinedValue); // Should throw InvalidOperationException var ex = Assert.Throws <InvalidOperationException>(() => wall2.UnjoinGeometry(floor)); Assert.AreEqual(ex.Message, expectedNotJoinedExceptionMessages); }
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI. ExternalCommandData commandData, ref string message, ElementSet elements) { Tracer.Listeners.Add(new System.Diagnostics.EventLogTraceListener("Application")); Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; try { IList <Wall> walls = new FilteredElementCollector(doc) .OfClass(typeof(Wall)) .WhereElementIsNotElementType() .Cast <Wall>() .ToList(); Tracer.Write("All the walls in the project: " + walls.Count); foreach (Wall wall in walls) { IList <Element> intrudingWalls = GetWallsIntersectBoundingBox(doc, wall); Tracer.Write(string.Format("Wall {0} is intersected by {1} walls", wall.Id.ToString(), intrudingWalls.Count)); using (Transaction t = new Transaction(doc, "Join walls")) { t.Start(); foreach (Element elem in intrudingWalls) { if (((Wall)elem).WallType.Kind == WallKind.Curtain) { continue; } try { if (!JoinGeometryUtils.AreElementsJoined(doc, wall, elem)) { JoinGeometryUtils.JoinGeometry(doc, wall, elem); } } catch (Exception ex) { Tracer.Write(string.Format("{0}\nWall: {1} cannot be joined to {2}", ex.Message, wall.Id.ToString(), elem.Id.ToString())); continue; } } t.Commit(); } } return(Autodesk.Revit.UI.Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Autodesk.Revit.UI.Result.Cancelled); } catch (Exception ex) { Tracer.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Autodesk.Revit.UI.Result.Failed); } }
private void WallJoinColumns(Document doc, List <Wall> wallList) { foreach (Wall wal in wallList) { Solid walSd = bc.AllSolid_Of_Element(wal)[0]; ElementIntersectsSolidFilter sdFilter = new ElementIntersectsSolidFilter(walSd); IList <Element> joinElemList = new FilteredElementCollector(doc).WherePasses(sdFilter).ToElements(); Transaction transJoin = new Transaction(doc, "连接"); transJoin.Start(); foreach (Element e in joinElemList) { //排除掉自己本身 if (e.Id.IntegerValue == wal.Id.IntegerValue) { continue; } //是板梁柱的话 if (e is Floor || e.Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralFraming || e.Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralColumns) { SubTransaction subTrans = new SubTransaction(doc); subTrans.Start(); if (JoinGeometryUtils.AreElementsJoined(doc, e, wal) == false) { JoinGeometryUtils.JoinGeometry(doc, e, wal); } subTrans.Commit(); if (JoinGeometryUtils.IsCuttingElementInJoin(doc, e, wal) == false) { JoinGeometryUtils.SwitchJoinOrder(doc, e, wal); } } } transJoin.Commit(); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; Selection sel = commandData.Application.ActiveUIDocument.Selection; List <ElementId> selids = sel.GetElementIds().ToList(); if (selids.Count == 0) { message = "Выберите элементы"; return(Result.Failed); } using (Transaction t = new Transaction(doc)) { t.Start("Отсоединение элементов"); foreach (ElementId selId in selids) { Element elem = doc.GetElement(selId); List <ElementId> ids = JoinGeometryUtils.GetJoinedElements(doc, elem).ToList(); foreach (ElementId id in ids) { Element elem2 = doc.GetElement(id); JoinGeometryUtils.UnjoinGeometry(doc, elem, elem2); } doc.Regenerate(); } t.Commit(); } return(Result.Succeeded); }
public JoinedGeometryCtrl(List <Element> _elems) { this.elements = _elems; var count = _elems.Count; var doc = _elems.First().Document; for (int i = 0; i < count - 1; i++) { var e1 = _elems[i]; for (int j = i + 1; j < count; j++) { var e2 = _elems[j]; if (JoinGeometryUtils.AreElementsJoined(doc, e1, e2)) { if (joinMap.ContainsKey(e1.Id) == false) { joinMap[e1.Id] = new List <ElementId>() { e2.Id }; } else { joinMap[e1.Id].Add(e2.Id); } } } } }
public static ElementId CreateJoinedWall(Document doc, ElementId wallId, FamilyInstance familyInstance) { //create a line to represent the wall center line var line = Line.CreateBound(XYZ.Zero, XYZ.BasisX); //find first level var collector = new FilteredElementCollector(doc); var filter = new ElementClassFilter(typeof(Level)); var level = collector.WherePasses(filter).FirstElement() as Level; //create wall var wall = Wall.Create(doc, line, level.Id, false); //save the id so we can delete the wall later wallId = wall.Id; //if the selected element var subIds = familyInstance.GetSubComponentIds(); if (subIds.Count > 0) { foreach (var id in subIds) { var subelement = doc.GetElement(id); JoinGeometryUtils.JoinGeometry(doc, wall, subelement); } } else { JoinGeometryUtils.JoinGeometry(doc, wall, familyInstance); } return(wallId); }
/// <summary> /// 板与梁和柱的连接 /// </summary> /// <param name="levList">标高集合</param> /// <param name="floorList">楼板集合</param> /// <param name="doc"> 项目文档</param> private void FloorJoinBeamAndColumn(List <Level> levList, List <Floor> floorList, Document doc) { foreach (Floor fl in floorList) { string flMat = fl.FloorType.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsValueString(); List <FamilyInstance> colElemList = JoinGeometryUtils.GetJoinedElements(doc, fl).Where(m => doc.GetElement(m). GetType() == typeof(FamilyInstance) && doc.GetElement(m).Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralColumns).ToList().ConvertAll(m => doc.GetElement(m) as FamilyInstance); List <FamilyInstance> beamElemList = JoinGeometryUtils.GetJoinedElements(doc, fl).Where(m => doc.GetElement(m).GetType() == typeof(FamilyInstance) && doc.GetElement(m).Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralFraming).ToList().ConvertAll(m => doc.GetElement(m) as FamilyInstance); using (Transaction tran = new Transaction(doc)) { tran.Start("Join"); foreach (FamilyInstance beam in beamElemList) { string beamMat = beam.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsValueString(); //如果材质相同,则板剪梁 if (beamMat == flMat) { if (JoinGeometryUtils.IsCuttingElementInJoin(doc, beam, fl)) { JoinGeometryUtils.SwitchJoinOrder(doc, beam, fl); } } else//如果材质不同,则梁剪板 { if (JoinGeometryUtils.IsCuttingElementInJoin(doc, fl, beam)) { JoinGeometryUtils.SwitchJoinOrder(doc, beam, fl); } } } foreach (FamilyInstance col in colElemList) { string colMat = col.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsValueString(); //如果材质相同则板剪柱 if (colMat == flMat) { if (JoinGeometryUtils.IsCuttingElementInJoin(doc, col, fl)) { JoinGeometryUtils.SwitchJoinOrder(doc, fl, col); } } //如果材质不同则柱剪板 else { if (JoinGeometryUtils.IsCuttingElementInJoin(doc, fl, col)) { JoinGeometryUtils.SwitchJoinOrder(doc, fl, col); } } } tran.Commit(); } } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Get UIdocument UIDocument uidoc = commandData.Application.ActiveUIDocument; //Get Document Document doc = uidoc.Document; try { //Get elements of Category var eles = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns) .WhereElementIsNotElementType() .ToElements(); using (var tran = new Transaction(doc, "Calculator Formwork Area for Element")) { tran.Start(); foreach (var ele in eles) { //Get BoundingBox from Element BoundingBoxXYZ boundingBox = ele.get_BoundingBox(null); //Get Outline Outline outline = new Outline(boundingBox.Min, boundingBox.Max); BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(outline); //BoundingBoxIntersectsFilter invertFilter = new BoundingBoxIntersectsFilter(outline,true); var eleIntersect = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .WherePasses(filter) .ToElements(); foreach (var item in eleIntersect) { var joined = JoinGeometryUtils.AreElementsJoined(doc, ele, item); if (joined == true) { JoinGeometryUtils.UnjoinGeometry(doc, ele, item); //JoinGeometryUtils.JoinGeometry(doc, ele, item); //JoinGeometryUtils.SwitchJoinOrder(doc, ele, item); } JoinGeometryUtils.JoinGeometry(doc, ele, item); //JoinGeometryUtils.SwitchJoinOrder(doc, ele, item); } } tran.Commit(); } return(Result.Succeeded); } catch (Exception exception) { message = exception.Message; return(Result.Failed); } }
private void joiningLining(Document doc, Floor myCuttingFloor) { Element element = myCuttingFloor as Element; GeometryElement geomElement = element.get_Geometry(new Options()); Solid solid = null; foreach (GeometryObject geomObj in geomElement) { solid = geomObj as Solid; if (solid != null) { break; } } FilteredElementCollector collector = new FilteredElementCollector(doc); collector.WherePasses(new ElementIntersectsSolidFilter(solid)); // Apply intersection filter to find matches //TaskDialog.Show("Revit", collector.Count() + " family instances intersect with the selected element (" + element.Category.Name + " id:" + element.Id.ToString() + ")"); List <ElementId> myListInter = new List <ElementId>(); foreach (Element myE in collector) { if (myE.Id != element.Id) { myListInter.Add(myE.Id); } } // Joint try { using (Transaction trans = new Transaction(doc, "Join Floor")) { trans.Start(); foreach (ElementId myEId in myListInter) { if (!JoinGeometryUtils.AreElementsJoined(doc, doc.GetElement(myEId), element)) { JoinGeometryUtils.JoinGeometry(doc, doc.GetElement(myEId), element); //JoinGeometryUtils.UnjoinGeometry(doc, doc.GetElement(myEId), element); } } trans.Commit(); } } catch (Exception e) { TaskDialog.Show("Error", e.Message); } }
public static List <global::Revit.Elements.Element> JoinedElements(global::Revit.Elements.Element element) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //the element filter, this just filters out type elements. Autodesk.Revit.DB.ElementFilter elemFilter = new ElementIsElementTypeFilter(true); //the joined element ids ICollection <ElementId> elemIds = JoinGeometryUtils.GetJoinedElements(doc, element.InternalElement); //get the elements List <global::Revit.Elements.Element> elems = new List <global::Revit.Elements.Element>(elemIds.Select(e => doc.GetElement(new ElementId(e.IntegerValue)).ToDSType(true))); return(elems); }
/// <summary> /// 返回被剪切的梁集合 /// </summary> /// <param name="beamList">梁集合</param> /// /// <param name="doc">项目文档</param> public static List <FamilyInstance> JoinBeamToBeam(List <FamilyInstance> beamList, Document doc) { using (Transaction trans = new Transaction(doc, "梁连接")) { //存储被剪切(包含即剪切其它梁又被其他梁剪切)的梁实例 List <FamilyInstance> joinBeamList = new List <FamilyInstance>(); //存储已经与其它构件处理过连接关系的构件 List <FamilyInstance> hasJoinBeamList = new List <FamilyInstance>(); //遍历梁的集合 foreach (FamilyInstance fi1 in beamList) { trans.Start(); foreach (FamilyInstance fi2 in beamList) { //排除已经处理过连接关系的构件 if (hasJoinBeamList.Count != 0 && hasJoinBeamList.Where(m => m.Id.IntegerValue == fi2.Id.IntegerValue).Count() != 0) { continue; } //排除构件本身 if (fi2.Id.IntegerValue == fi1.Id.IntegerValue) { continue; } //比较构件高低 double h1 = fi1.Symbol.LookupParameter("h").AsDouble() * 304.8; double h2 = fi2.Symbol.LookupParameter("h").AsDouble() * 304.8; FamilyInstance f1 = h1 >= h2 ? fi1 : fi2; FamilyInstance f2 = h1 >= h2 ? fi2 : fi1; if (JoinGeometryUtils.AreElementsJoined(doc, f1, f2)) { bool b = JoinGeometryUtils.IsCuttingElementInJoin(doc, f1, f2); //梁高大剪切梁高小的 if (b == false) { SubTransaction sbTrans = new SubTransaction(doc); sbTrans.Start(); JoinGeometryUtils.SwitchJoinOrder(doc, f1, f2); sbTrans.Commit(); } if (joinBeamList.Count == 0 || joinBeamList.Where(m => m.Id.IntegerValue == f2.Id.IntegerValue).Count() == 0) { joinBeamList.Add(f2); } } } hasJoinBeamList.Add(fi1); trans.Commit(); } return(joinBeamList); } }
public static void joinGeoByTwoCategories(Document doc, BuiltInCategory firstCategory, BuiltInCategory secondCategory) { FilteredElementCollector coll = new FilteredElementCollector(doc); // 篩選條件牆的篩選器 ElementCategoryFilter filterFirstCategory = new ElementCategoryFilter(firstCategory); IList <Element> FirstCategoryElements = coll.WherePasses(filterFirstCategory) .WhereElementIsNotElementType().ToElements(); //因為元件接合要做寫入改動,因此要將它放入交易 //針對所有元件作自動接合 foreach (Element firstElement in FirstCategoryElements) { BoundingBoxXYZ bbx = firstElement.get_BoundingBox(null); //從第一元件取得「邊界長方體」(包覆元件邊界的長方體,如果元件本身是長方體,就會完全包覆) //OutLine是一條線,此處等於直接拿包覆長方體的對角線來定義它 Outline outline = new Outline(bbx.Min, bbx.Max);//Min及Max各是一個點,都能存取XYZ座標 BoundingBoxIntersectsFilter filterIntersection = new BoundingBoxIntersectsFilter(outline); //這個過濾器會取得「所有和這個BoundingBox相交的BoundingBox,並且傳回其所代表之元件」 ElementCategoryFilter filterSecondCategory = new ElementCategoryFilter(secondCategory); //然後在相交元件當中,我只想先處理第一類別與第二類別的相交,所以需要再一個篩選器 LogicalAndFilter andfilter = new LogicalAndFilter(filterIntersection, filterSecondCategory); //用交集篩選器將它們組合起來 IList <Element> adjacents = new FilteredElementCollector(doc).WherePasses(andfilter). WhereElementIsNotElementType().ToElements(); //以上一行選取所有和第一元件相鄰,而且屬於第二類別的元件,把整個doc放進Collector後再濾出通過篩選器的元件 foreach (Element secondElement in adjacents) { //MessageBox.Show(secondElement.Id + "\n" + secondElement.Category.Name); //debug Transaction trans = new Transaction(doc); try { trans.Start("join"); //開始交易(接合) if (JoinGeometryUtils.AreElementsJoined(doc, firstElement, secondElement) == true) //如果兩個元件已接合 { JoinGeometryUtils.UnjoinGeometry(doc, firstElement, secondElement); //先解除接合,因為我假設它不是我要的結果 } //以上那個動作有點近似我們在Revit裡頭除了「接合」、「取消接合」以外,也可以「改變接合順序」 JoinGeometryUtils.JoinGeometry(doc, firstElement, secondElement); //再重新接合,但原本就處於未接合的元件也會被接合 } catch (Exception ex) { //MessageBox.Show(ex.ToString()); } finally //這裡刻意讓finally陳述句登場,只是強調無論如何都要做交易的commit { trans.Commit(); } } //end inner foreach } //end outer foreach } //end fun
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Application app = commandData.Application.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; ICollection<ElementId> elementIds = new List<ElementId>(); if (uidoc.Selection.GetElementIds().Count>0) { elementIds = uidoc.Selection.GetElementIds(); } else { try { elementIds = uidoc.Selection.PickObjects(ObjectType.Element, new FloorSelectFilter(), "Pick floors").Select(q => q.ElementId).ToList(); } 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, "Switch join order")) { t1.Start(); foreach(ElementId floorId in elementIds) { Floor floor = doc.GetElement(floorId) as Floor; BoundingBoxXYZ boundingBox = floor.get_BoundingBox(doc.ActiveView); BoundingBoxIntersectsFilter bbFilter = new BoundingBoxIntersectsFilter(new Outline(boundingBox.Min, boundingBox.Max)); FilteredElementCollector columnCollector = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_StructuralColumns).WherePasses(bbFilter); foreach (Element column in columnCollector) { if (JoinGeometryUtils.AreElementsJoined(doc, floor, column)) { if(JoinGeometryUtils.IsCuttingElementInJoin(doc, floor, column)) { JoinGeometryUtils.SwitchJoinOrder(doc, floor, column); } } } } t1.Commit(); } return Result.Succeeded; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; var columnCollecter = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns).OfClass(typeof(FamilyInstance)); List <FamilyInstance> columnlist = columnCollecter.ToList().ConvertAll(x => x as FamilyInstance); foreach (FamilyInstance column in columnlist) { var columnIntersectsFilter = new ElementIntersectsElementFilter(column); var filteredElementCollector = new FilteredElementCollector(doc); //文档中过滤出所有和柱相交的元素集合 List <Element> columnsIntersectList = filteredElementCollector.WherePasses(columnIntersectsFilter).ToList(); var coulmnIntersectList = from elem in columnsIntersectList where elem.Category.Id == new ElementId(-2001320) //梁 || elem.Category.Id == new ElementId(-2001330) //柱 || elem.Category.Id == new ElementId(-2000011) && (elem as Wall).WallType.Kind == WallKind.Basic //基本墙 || elem.Category.Id == new ElementId(-2000032) //板 select elem; foreach (Element elem in columnsIntersectList) { Transaction ts = new Transaction(doc); ts.Start("cut"); if (JoinGeometryUtils.AreElementsJoined(doc, column, elem) == false) { try { JoinGeometryUtils.JoinGeometry(doc, elem, column); } catch { } } else { if (JoinGeometryUtils.IsCuttingElementInJoin(doc, column, elem) == false) { JoinGeometryUtils.SwitchJoinOrder(doc, column, elem); } } ts.Commit(); } } return(Result.Succeeded); }
public void UnjoinAll() { var doc = this.elements.First().Document; foreach (var p in this.joinMap) { var e1 = doc.GetElement(p.Key); var ids = p.Value; foreach (var id in ids) { var e2 = doc.GetElement(id); JoinGeometryUtils.UnjoinGeometry(doc, e1, e2); } } }
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(); if (elementIds.Count != 0) { List <Element> list = Method.GeometryFilter(document, elementIds); int num = 0; if (list.Count > 1) { Combinations <Element> combinations = new Combinations <Element>(list, 2, GenerateOption.WithoutRepetition); Transaction val = new Transaction(document); val.Start("Merger Element"); FailureHandlingOptions failureHandlingOptions = val.GetFailureHandlingOptions(); MyFailuresPreProcessor myFailuresPreProcessor = new MyFailuresPreProcessor(); failureHandlingOptions.SetFailuresPreprocessor(myFailuresPreProcessor); val.SetFailureHandlingOptions(failureHandlingOptions); foreach (List <Element> item in combinations) { if (!JoinGeometryUtils.AreElementsJoined(document, item[0], item[1])) { try { JoinGeometryUtils.JoinGeometry(document, item[0], item[1]); num++; } catch { } } } MessageBox.Show(num.ToString() + " Pairs Elements Successfully Join.", "ElementMerger"); val.Commit(); } else if (list.Count == 1) { TaskDialog.Show("ElementMerger", "Only One Element Selected"); } } else { TaskDialog.Show("ElementMerger", "None Element Selected"); } return(0); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; View activeView = doc.ActiveView; IList <Reference> selectedElements = uidoc.Selection.PickObjects(ObjectType.Element, "Select Elements to be joined"); int count = 0; using (Transaction t = new Transaction(doc, "Unjoin all")) { t.Start(); foreach (Reference eleRef in selectedElements) { try { ICollection <ElementId> elementJoined = JoinGeometryUtils.GetJoinedElements(doc, doc.GetElement(eleRef)); foreach (ElementId eid in elementJoined) { JoinGeometryUtils.UnjoinGeometry(doc, doc.GetElement(eleRef), doc.GetElement(eid)); } count += 1; } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } } t.Commit(); } TaskDialog.Show("Result", String.Format("{0} have been unjoined", count)); return(Result.Succeeded); }
private void CreateParapetWall(CurveArray curveArray) { foreach (Curve curve in curveArray) { XYZ curveMiddlePoint = GetCurveMiddlePoint(curve); WallType wallType = revitDB.GetWallType(Properties.Settings.Default.WallTypeName); Wall parapetWall = Wall.Create(document, curve, wallType.Id, roofLevel.Id, UnitUtils.ConvertToInternalUnits(0.8, UnitTypeId.Meters), 0, false, false); Wall wall = hb.FindWall(curveMiddlePoint, baseLevel); if (wall != null) { try { JoinGeometryUtils.JoinGeometry(document, wall, parapetWall); } catch { continue; } } } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uidoc = commandData.Application.ActiveUIDocument; var doc = uidoc.Document; var connForm = new ConnectElmFrm(uidoc); if (connForm.ShowDialog() != DialogResult.OK) { return(Result.Cancelled); } doc.AutoTransaction(() => { var combins = new CombinableElementArray(); var elms = connForm.Elms; elms.OfType <CombinableElement>().ToList().ForEach(f => combins.Append(f)); if (doc.IsFamilyDocument && combins.Size >= 2) { doc.CombineElements(combins); } else if (!doc.IsFamilyDocument && elms.Count >= 2) { elms.ForEach(f1 => elms.ForEach(f2 => { ExceptionUtil.AutoTry(() => { if (f1 == f2) { return; } if (!doc.CrossSpaceBox(f1, f2)) { return; } JoinGeometryUtils.JoinGeometry(doc, f1, f2); }); })); } }); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; // code try { FilteredElementCollector collectorColums = new FilteredElementCollector(doc); List <Element> listColumns = collectorColums.OfCategory(BuiltInCategory.OST_StructuralColumns) .WhereElementIsNotElementType().ToElements().ToList(); FilteredElementCollector collectorBeams = new FilteredElementCollector(doc); List <Element> listBeams = collectorBeams.OfCategory(BuiltInCategory.OST_StructuralFraming) .WhereElementIsNotElementType().ToElements().ToList(); Transaction tran = new Transaction(doc); tran.Start("Switch Beam PRT Column"); int count = 0; foreach (Element column in listColumns) { foreach (Element beam in listBeams) { if (JoinGeometryUtils.AreElementsJoined(doc, column, beam)) { if (!JoinGeometryUtils.IsCuttingElementInJoin(doc, beam, column)) { JoinGeometryUtils.SwitchJoinOrder(doc, beam, column); count++; } } } } tran.Commit(); MessageBox.Show($"Auto switch {count} pairs of beam column done!"); } catch (Exception ex) { } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; // code try { FilteredElementCollector collectorColums = new FilteredElementCollector(doc); List <Element> listColumns = collectorColums.OfCategory(BuiltInCategory.OST_StructuralColumns) .WhereElementIsNotElementType().ToElements().ToList(); FilteredElementCollector collectorDeck = new FilteredElementCollector(doc); List <Element> listDecks = collectorDeck.OfCategory(BuiltInCategory.OST_Floors) .WhereElementIsNotElementType().ToElements().ToList(); Transaction tran = new Transaction(doc); tran.Start("Join beam to deck"); int count = 0; foreach (Element deck in listDecks) { foreach (Element column in listColumns) { try { JoinGeometryUtils.JoinGeometry(doc, deck, column); count++; } catch (Exception ex) { } } } tran.Commit(); MessageBox.Show($"Auto join {count} pairs of column deck done!"); } catch (Exception ex) { } return(Result.Succeeded); }
static internal void JoinBeamToWalls(FamilyInstance targetBeam, Document doc) { ElementIntersectsElementFilter elementFilter = new ElementIntersectsElementFilter(targetBeam); IList <Element> WallsIntersectingBeam = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls) .OfClass(typeof(Wall)).WhereElementIsNotElementType().WherePasses(elementFilter).ToList(); foreach (Element currentWall in WallsIntersectingBeam) { try { JoinGeometryUtils.JoinGeometry(doc, targetBeam, currentWall); } catch { } } }
private void setBeJoined(Document doc, Element myBeJoined) { ICollection <ElementId> myListElemIdsJoined = JoinGeometryUtils.GetJoinedElements(doc, myBeJoined); using (Transaction trans = new Transaction(doc, "Switch Join")) { trans.Start(); foreach (ElementId myElemId in myListElemIdsJoined) { if (!JoinGeometryUtils.IsCuttingElementInJoin(doc, doc.GetElement(myElemId), myBeJoined)) { JoinGeometryUtils.SwitchJoinOrder(doc, doc.GetElement(myElemId), myBeJoined); } } trans.Commit(); } }
public void CanUnjoinListOfElements() { var wall1 = ElementSelector.ByElementId(184176, true); var wall2 = ElementSelector.ByElementId(207960, true); var floor = ElementSelector.ByElementId(208259, true); var doc = DocumentManager.Instance.CurrentDBDocument; // Are joined bool originalWall1AndWall2JoinedValue = JoinGeometryUtils.AreElementsJoined(doc, wall1.InternalElement, wall2.InternalElement); Assert.AreEqual(true, originalWall1AndWall2JoinedValue); // Are joined bool originalWall1AndFloorJoinedValue = JoinGeometryUtils.AreElementsJoined(doc, wall1.InternalElement, floor.InternalElement); Assert.AreEqual(true, originalWall1AndFloorJoinedValue); // Are not joined bool originalWall2AndFloorJoinedValue = JoinGeometryUtils.AreElementsJoined(doc, wall2.InternalElement, floor.InternalElement); Assert.AreEqual(false, originalWall2AndFloorJoinedValue); var elementList = new List <Element>() { wall1, wall2, floor }; Element.UnjoinAllGeometry(elementList); bool newWall1AndWall2JoinedValue = wall1.AreJoined(wall2); bool newWall1AndFloorJoinedValue = wall1.AreJoined(floor); bool newWall2AndFloorJoinedValue = wall2.AreJoined(floor); // Are joined should have changed Assert.AreNotEqual(newWall1AndWall2JoinedValue, originalWall1AndWall2JoinedValue); // Are joined should have changed Assert.AreNotEqual(newWall1AndFloorJoinedValue, originalWall1AndFloorJoinedValue); // Are joined should be the same Assert.AreEqual(newWall2AndFloorJoinedValue, originalWall2AndFloorJoinedValue); }
private void JoinGeometry(Document doc, Dictionary <ElementId, ElementId> skirtingDictionary) { foreach (ElementId skirtingId in skirtingDictionary.Keys) { Wall skirtingWall = doc.GetElement(skirtingId) as Wall; if (skirtingWall != null) { Parameter wallJustification = skirtingWall.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM); wallJustification.Set(3); Wall baseWall = doc.GetElement(skirtingDictionary[skirtingId]) as Wall; if (baseWall != null) { JoinGeometryUtils.JoinGeometry(doc, skirtingWall, baseWall); } } } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uidoc = commandData.Application.ActiveUIDocument; var doc = uidoc.Document; var eles = new FilteredElementCollector(doc).OfCategory((BuiltInCategory.OST_StructuralColumns)) .WhereElementIsNotElementType() .ToElements(); using (var tran = new Transaction(doc, "Join Floor and Column")) { tran.Start(); foreach (var ele in eles) { var boundingBox = ele.get_BoundingBox(null); var outline = new Outline(boundingBox.Min, boundingBox.Max); var filter = new BoundingBoxIntersectsFilter(outline); var collectors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls) .WhereElementIsNotElementType() .WherePasses(filter) .ToElements(); foreach (var item in collectors) { //Options options = new Options(); //options.ComputeReferences = true; //options.DetailLevel = ViewDetailLevel.Fine; //GeometryElement geoElement = item.get_Geometry(options); bool joined = JoinGeometryUtils.AreElementsJoined(doc, ele, item); if (joined == true) { JoinGeometryUtils.UnjoinGeometry(doc, ele, item); } JoinGeometryUtils.JoinGeometry(doc, ele, item); //JoinGeometryUtils.SwitchJoinOrder(doc, ele, item); } } tran.Commit(); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { _uiapp = commandData.Application; _uidoc = _uiapp.ActiveUIDocument; _doc = _uidoc.Document; try { List <FamilyInstance> bn_pvList = (from FamilyInstance beam in new FilteredElementCollector(_doc) .OfCategory(BuiltInCategory.OST_StructuralFraming) .OfClass(typeof(FamilyInstance)) .Cast <FamilyInstance>() where beam.Name.Contains("BN") || beam.Name.Contains("TAL") select beam) .ToList(); TaskDialog.Show("Revit", $"{bn_pvList.Count()} BN/Talon"); using (Transaction tx = new Transaction(_doc)) { tx.Start("Unjoin"); foreach (FamilyInstance bn in bn_pvList) { IList <ElementId> eleList = JoinGeometryUtils.GetJoinedElements(_doc, bn).ToList(); foreach (ElementId id in eleList) { Element ele = _doc.GetElement(id); JoinGeometryUtils.UnjoinGeometry(_doc, bn, ele); } } tx.Commit(); } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Result.Failed); } }
public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements) { var uiapp = revit.Application; var doc = uiapp.ActiveUIDocument.Document; var uidoc = uiapp.ActiveUIDocument; var allWalls = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_Walls) .WhereElementIsNotElementType(); var allColumns = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_Columns) .WhereElementIsNotElementType(); // collect the wall ids var columnIds = allColumns.ToElementIds(); // place all your actions in a single transaction for easy undo var trans = new Transaction(doc, "AutoJoinFunction"); trans.Start(); foreach (Element wall in allWalls) { var wbb = wall.get_BoundingBox(doc.ActiveView); // see https://apidocs.co/apps/revit/2020/901f78a0-1f6c-217b-ea48-8b404324e88b.htm var bboxChecker = new FilteredElementCollector(doc, columnIds) .WherePasses( new BoundingBoxIntersectsFilter( new Outline(wbb.Min, wbb.Max) ) ); foreach (Element column in bboxChecker) { JoinGeometryUtils.JoinGeometry(doc, column, wall); } } trans.Commit(); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; //Application app = uiapp.Application; Document doc = uidoc.Document; // get all walls on the active view FilteredElementCollector floors = new FilteredElementCollector(doc, doc.ActiveView.Id); floors.OfClass(typeof(Floor)); foreach (Floor w in floors) { // get columns on the active view FilteredElementCollector beams = new FilteredElementCollector(doc, doc.ActiveView.Id) .OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_StructuralFraming); // as we don't want all columns, let's filter // by the wall bounding box (intersect) BoundingBoxXYZ bb = w.get_BoundingBox(doc.ActiveView); Outline outline = new Outline(bb.Min, bb.Max); BoundingBoxIntersectsFilter bbfilter = new BoundingBoxIntersectsFilter(outline); beams.WherePasses(bbfilter); using (Transaction t = new Transaction(doc, "Join Elements")) { t.Start(); foreach (FamilyInstance b in beams) { JoinGeometryUtils.JoinGeometry(doc, w, b); } t.Commit(); } } return(Result.Succeeded); }
/// <summary> /// To connect elements on adjacent floor. /// </summary> /// <param name="doc"></param> /// <param name="wallGroups"></param> /// <returns></returns> private static int JoinElmByAdjacentFloor <T>(Document doc, IReadOnlyList <IGrouping <double, T> > wallGroups) where T : Element { var result = 0; for (var i = 0; i < wallGroups.Count - 1; i++) { foreach (var walli in wallGroups[i]) { if (!(walli.Location is LocationCurve c1)) { continue; } foreach (var wallj in wallGroups[i + 1]) { if (!(wallj.Location is LocationCurve c2)) { continue; } if (!doc.RejectSpaceBox(walli, wallj)) { continue; } if ((c1.Curve as Line).GetSpacePosition(c2.Curve as Line, out _) != GeometryPosition.Parallel) { continue; } ExceptionUtil.AutoTry(() => { JoinGeometryUtils.JoinGeometry(doc, walli, wallj); result++; }); } } } return(result); }