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(); } }
/// <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(); } } }
/// <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 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 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("SwitchJoinOrder"); 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.SwitchJoinOrder(document, item[0], item[1]); num++; } catch { } } } MessageBox.Show(num.ToString() + " Pairs Elements Successfully Switch Join Order.", "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; // 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); }
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 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; Reference firstElement = uidoc.Selection.PickObject(ObjectType.Element, "Select First Element"); IList <Reference> selectedElements = uidoc.Selection.PickObjects(ObjectType.Element, "Select Elements to be joined"); int count = 0; using (Transaction t = new Transaction(doc, "Switch join")) { t.Start(); foreach (Reference eleRef in selectedElements) { try { JoinGeometryUtils.SwitchJoinOrder(doc, doc.GetElement(firstElement), doc.GetElement(eleRef)); count += 1; } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } } t.Commit(); } TaskDialog.Show("Result", String.Format("{0} have been switched", count)); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Debug.Listeners.Clear(); Debug.Listeners.Add(new RbsLogger.Logger("JoinByOrder")); Document doc = commandData.Application.ActiveUIDocument.Document; Selection sel = commandData.Application.ActiveUIDocument.Selection; ICollection <ElementId> ids = sel.GetElementIds(); if (ids.Count == 0) { message = "Выберите элементы для соединения"; return(Result.Failed); } if (ids.Count > 100) { TaskDialog dialog = new TaskDialog("Предупреждение"); dialog.MainInstruction = "Выделено большое количество элементов (" + ids.Count.ToString() + "), их соединение может привести к снижение быстродействия модели. Продолжить?"; dialog.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel; if (dialog.Show() != TaskDialogResult.Ok) { return(Result.Cancelled); } } List <Element> elems = new List <Element>(); foreach (ElementId id in ids) { Element elem = doc.GetElement(id); elems.Add(elem); } List <MyCategory> uniqCats = elems .Select(i => (BuiltInCategory)i.Category.Id.IntegerValue) .Distinct() .Select(i => new MyCategory(doc, i)) .ToList(); FormSetJoinOrder form = new FormSetJoinOrder(uniqCats); if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return(Result.Cancelled); } Dictionary <BuiltInCategory, int> categoriesPriority = form.Cats.ToDictionary(i => i._category, j => j.priority); int counter = 0; using (Transaction t = new Transaction(doc)) { t.Start("Соединение " + elems.Count.ToString() + " элементов"); foreach (Element elem1 in elems) { foreach (Element elem2 in elems) { if (elem2.Equals(elem1)) { continue; } bool alreadyJoined = JoinGeometryUtils.AreElementsJoined(doc, elem1, elem2); bool isIntersects = Intersection.CheckElementsIsIntersect(doc, elem1, elem2); if (!isIntersects && !alreadyJoined) { continue; } try { JoinGeometryUtils.JoinGeometry(doc, elem1, elem2); } catch { } bool isElemJoined = JoinGeometryUtils.AreElementsJoined(doc, elem1, elem2); if (!isElemJoined) { continue; } bool isFirstElemMain = JoinGeometryUtils.IsCuttingElementInJoin(doc, elem1, elem2); int firstElemPriority = categoriesPriority[(BuiltInCategory)elem1.Category.Id.IntegerValue]; int secondElemPriority = categoriesPriority[(BuiltInCategory)elem2.Category.Id.IntegerValue]; if (isFirstElemMain && firstElemPriority > secondElemPriority) { JoinGeometryUtils.SwitchJoinOrder(doc, elem1, elem2); counter++; } } } doc.Regenerate(); t.Commit(); } if (counter == 0) { message = "Все соединения уже соответствуют заданному приоритету"; return(Result.Cancelled); } return(Result.Succeeded); }
private void Button1_Click(object sender, EventArgs e) { //Code here string comboA = comboBox1.SelectedItem.ToString(); string comboB = comboBox2.SelectedItem.ToString(); if (comboA == comboB) { MessageBox.Show("Please select diffirent combo above"); return; } bool checkJoin = radioButton1.Checked; bool checkUnJoin = radioButton2.Checked; bool checkSwitchJoin = radioButton3.Checked; // Get data for combo A,B List <Element> listA = new List <Element>(); List <Element> listB = new List <Element>(); FilteredElementCollector collectorA = new FilteredElementCollector(doc); switch (comboA) { case "Beam": listA = collectorA.OfCategory(BuiltInCategory.OST_StructuralFraming) .WhereElementIsNotElementType().ToElements().ToList(); break; case "Column": listA = collectorA.OfCategory(BuiltInCategory.OST_StructuralColumns) .WhereElementIsNotElementType().ToElements().ToList(); break; case "Deck": listA = collectorA.OfCategory(BuiltInCategory.OST_Floors) .WhereElementIsNotElementType().ToElements().ToList(); break; } FilteredElementCollector collectorB = new FilteredElementCollector(doc); switch (comboB) { case "Beam": listB = collectorB.OfCategory(BuiltInCategory.OST_StructuralFraming) .WhereElementIsNotElementType().ToElements().ToList(); break; case "Column": listB = collectorB.OfCategory(BuiltInCategory.OST_StructuralColumns) .WhereElementIsNotElementType().ToElements().ToList(); break; case "Deck": listB = collectorB.OfCategory(BuiltInCategory.OST_Floors) .WhereElementIsNotElementType().ToElements().ToList(); break; } if (checkJoin) { Transaction tran = new Transaction(doc); tran.Start($"Auto Join {comboA} to {comboB}"); int count = 0; foreach (Element a in listA) { foreach (Element b in listB) { try { JoinGeometryUtils.JoinGeometry(doc, a, b); count++; } catch (Exception ex) { } } } tran.Commit(); MessageBox.Show($"Auto join {count} pairs of {comboA} {comboB} done!"); } else if (checkUnJoin) { Transaction tran = new Transaction(doc); tran.Start($"Auto UnJoin {comboA} to {comboB}"); int count = 0; foreach (Element a in listA) { foreach (Element b in listB) { try { JoinGeometryUtils.UnjoinGeometry(doc, a, b); count++; } catch (Exception ex) { } } } tran.Commit(); MessageBox.Show($"Auto Unjoin {count} pairs of {comboA} {comboB} done!"); } else if (checkSwitchJoin) { Transaction tran = new Transaction(doc); tran.Start("Switch Beam PRT Column"); int count = 0; foreach (Element a in listA) { foreach (Element b in listB) { if (JoinGeometryUtils.AreElementsJoined(doc, a, b)) { if (!JoinGeometryUtils.IsCuttingElementInJoin(doc, a, b)) { JoinGeometryUtils.SwitchJoinOrder(doc, a, b); count++; } else { JoinGeometryUtils.SwitchJoinOrder(doc, b, a); count++; } } } } tran.Commit(); MessageBox.Show($"Auto switch {count} pairs of {comboA} {comboB} done!"); } else { MessageBox.Show("Please select mode before run."); } }
//---// private void button1_Click(object sender, EventArgs e) { //code here string chooseA = comboBoxA.SelectedItem.ToString(); string chooseB = comboBoxB.SelectedItem.ToString(); List <Element> listA = GetElementByKey(chooseA); List <Element> listB = GetElementByKey(chooseB); //Code if (AutoJoin.Checked) { //join try { Transaction tran = new Transaction(doc); tran.Start($"Join {chooseA} to {chooseB}"); int count = 0; foreach (Element a in listA) { foreach (Element b in listB) { try { JoinGeometryUtils.JoinGeometry(doc, a, b); count++; } catch (Exception exx) { } } } tran.Commit(); MessageBox.Show($"Auto Join {count} pairs of {chooseA} {chooseB} done!"); } catch (Exception ex) { } } else if (AutoUnJoin.Checked) { //Unjoin try { Transaction tran = new Transaction(doc); tran.Start($"UnJoin {chooseA} to {chooseB}"); int count = 0; foreach (Element a in listA) { foreach (Element b in listB) { try { JoinGeometryUtils.UnjoinGeometry(doc, a, b); count++; } catch (Exception exx) { } } } tran.Commit(); MessageBox.Show($"Auto UnJoin {count} pairs of {chooseA} {chooseB} done!"); } catch (Exception ex) { } } else if (SwitchJoin.Checked) { // Switch join try { Transaction tran = new Transaction(doc); tran.Start($"Switch {chooseA} PRT {chooseB}"); int count = 0; foreach (Element a in listA) { foreach (Element b in listB) { if (JoinGeometryUtils.AreElementsJoined(doc, a, b)) { if (!JoinGeometryUtils.IsCuttingElementInJoin(doc, b, a)) { JoinGeometryUtils.SwitchJoinOrder(doc, b, a); count++; } } } } tran.Commit(); MessageBox.Show($"Auto switchjoin {count} pairs of {chooseA} {chooseB} done!"); } catch (Exception ex) { } } else { MessageBox.Show("Please choose one option!"); } Close(); }
/// <summary> /// 梁柱连接 /// </summary> /// <param name="beamList">梁的实例</param> /// <param name="colList">柱子的实例</param> /// <param name="doc">项目文档</param> private void JoinBeamAndColumns(ref List <FamilyInstance> beamList, List <FamilyInstance> colList, Document doc) { if (colList.Count != 0 && beamList.Count != 0) { List <XYZ> colPosList = colList.ConvertAll(m => (m.Location as LocationPoint).Point); Level lev = doc.GetElement(beamList[0].Host.Id) as Level; List <FamilyInstance> BeamNotJoinNowColListList = new List <FamilyInstance>(); //需要改变定位线的梁、 List <ElementId> beamElemChnageIds = new List <ElementId>(); List <Line> beamLocationCurveList = new List <Line>(); foreach (FamilyInstance col in colList) { XYZ colPos = (col.Location as LocationPoint).Point; XYZ direction = -XYZ.BasisZ; double b = col.Symbol.LookupParameter("b").AsDouble(); double h = col.Symbol.LookupParameter("h").AsDouble(); double length = b > h ? b : h; double curveLoopWidth = length / 2 + 200 / 304.8; CurveLoop cuLoop = new CurveLoop(); double x = colPos.X; double y = colPos.Y; double z = lev.Elevation; //左上 XYZ p1 = new XYZ(x - curveLoopWidth, y + curveLoopWidth, z); //左下 XYZ p2 = p1 + new XYZ(0, -2 * curveLoopWidth, 0); //右下 XYZ p3 = p2 + new XYZ(2 * curveLoopWidth, 0, 0); //右上 XYZ p4 = p3 + new XYZ(0, 2 * curveLoopWidth, 0); Curve c1 = Line.CreateBound(p1, p2); Curve c2 = Line.CreateBound(p2, p3); Curve c3 = Line.CreateBound(p3, p4); Curve c4 = Line.CreateBound(p4, p1); cuLoop.Append(c1); cuLoop.Append(c2); cuLoop.Append(c3); cuLoop.Append(c4); Solid intersectSolid = GeometryCreationUtilities.CreateExtrusionGeometry(new List <CurveLoop>() { cuLoop }, direction, 200 / 304.8); ElementIntersectsSolidFilter ElemInsectSolidFilter = new ElementIntersectsSolidFilter(intersectSolid); IList <Element> beamNotJoinColList = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_StructuralFraming).WherePasses(ElemInsectSolidFilter).ToElements(). Where(m => !JoinGeometryUtils.AreElementsJoined(doc, m, col)).ToList(); //Transaction trans = new Transaction(doc, "创建内建模型"); //trans.Start(); //DirectShapeType drt = DirectShapeType.Create(doc, "实体", new ElementId(BuiltInCategory.OST_Parts)); //DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_Parts), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); //ds.SetShape(new List<GeometryObject>() { intersectSolid }); //ds.SetTypeId(drt.Id); //trans.Commit(); //TaskDialog.Show("biao", "uu"); foreach (Element e in beamNotJoinColList) { //判断是否发生了变化 bool pd = true; Line l = (e.Location as LocationCurve).Curve is Line ? (e.Location as LocationCurve).Curve as Line : null; if (l == null) { continue; } XYZ lp1 = l.GetEndPoint(0); XYZ lp2 = l.GetEndPoint(1); XYZ dirt = (lp1 - lp2) / lp1.DistanceTo(lp2); //当柱端点与梁端点相距不超过某个值是默认让其相交 XYZ pi = new XYZ(x, y, z); if (lp1.DistanceTo(pi) < curveLoopWidth) { if (dirt.IsAlmostEqualTo(new XYZ(0, 1, 0)) || dirt.IsAlmostEqualTo(new XYZ(0, -1, 0))) { lp1 = new XYZ(lp1.X, pi.Y, lev.Elevation); } else if (dirt.IsAlmostEqualTo(new XYZ(-1, 0, 0)) || dirt.IsAlmostEqualTo(new XYZ(1, 0, 0))) { lp1 = new XYZ(pi.X, lp1.Y, lev.Elevation); } else { continue; } } else if (lp2.DistanceTo(pi) < curveLoopWidth) { if (dirt.IsAlmostEqualTo(new XYZ(0, 1, 0)) || dirt.IsAlmostEqualTo(new XYZ(0, -1, 0))) { lp2 = new XYZ(lp2.X, pi.Y, lev.Elevation); } else if (dirt.IsAlmostEqualTo(new XYZ(-1, 0, 0)) || dirt.IsAlmostEqualTo(new XYZ(1, 0, 0))) { lp2 = new XYZ(pi.X, lp2.Y, lev.Elevation); } else { continue; } } else { pd = false; } if (pd == true) { if (beamElemChnageIds.Count() == 0 || beamElemChnageIds.Where(m => m == e.Id).Count() == 0) { beamElemChnageIds.Add(e.Id); beamLocationCurveList.Add(Line.CreateBound(lp1, lp2)); } else { int index = beamElemChnageIds.IndexOf(e.Id); Line indexLine = beamLocationCurveList.ElementAt(index); XYZ pone = indexLine.GetEndPoint(0); XYZ ptwo = indexLine.GetEndPoint(1); //变化的线 Line linelast1 = Line.CreateBound(pone, lp2); Line linelast2 = Line.CreateBound(lp1, ptwo); beamLocationCurveList[index] = linelast1.Length > linelast2.Length ? linelast1 : linelast2; } } } } //创建新的梁实例 using (Transaction transChange = new Transaction(doc)) { transChange.Start("join"); foreach (ElementId beamId in beamElemChnageIds) { int index = beamElemChnageIds.IndexOf(beamId); Element beam = doc.GetElement(beamId); (beam.Location as LocationCurve).Curve = beamLocationCurveList[index]; TaskDialog.Show("kaishi", "sdduas"); } transChange.Commit(); } using (Transaction trans = new Transaction(doc, "调整顺序")) { trans.Start(); //梁柱剪切关系 foreach (FamilyInstance col in colList) { foreach (FamilyInstance beam in beamList) { if (JoinGeometryUtils.AreElementsJoined(doc, beam, col) == true) { if (JoinGeometryUtils.IsCuttingElementInJoin(doc, beam, col)) { JoinGeometryUtils.SwitchJoinOrder(doc, col, beam); } } } } trans.Commit(); } } }