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); }
/// <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 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); }
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 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) { _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); } }
static void UnjoinElements(Document doc, Element selectedElem) { ICollection <ElementId> joinedElements = JoinGeometryUtils.GetJoinedElements(doc, selectedElem); if (joinedElements != null && joinedElements.Count > 0) { using (Transaction t = new Transaction(doc, "Unjoin Elements")) { t.Start(); foreach (ElementId id in joinedElements) { JoinGeometryUtils.UnjoinGeometry (doc, selectedElem, doc.GetElement(id)); } t.Commit(); } } m_selectedElem = selectedElem; m_selectedElemSolid = RvtGeometryUtils.GetSolid(m_selectedElem); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiapp = commandData.Application; var uidoc = uiapp.ActiveUIDocument; var doc = uidoc.Document; var sel = uidoc.Selection; var beam = sel.PickObject(ObjectType.Element).GetElement(doc) as FamilyInstance; var getcuttingelements = JoinGeometryUtils.GetJoinedElements(doc, beam).ToList(); var beamsolid = beam.get_Geometry(new Options() { DetailLevel = ViewDetailLevel.Fine }).GetSolidOfGeometryObject(); var othersolids = getcuttingelements.Select(m => m.GetElement(doc).get_Geometry(new Options() { DetailLevel = ViewDetailLevel.Fine })); var resultsolid = default(Solid); foreach (var othersolid in othersolids) { //resultsolid = BooleanOperationsUtils.ExecuteBooleanOperation(beamsolid as Solid, othersolids.First(),BooleanOperationsType.Difference) } //doc.DisplayUnitSystem return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var doc = commandData.Application.ActiveUIDocument.Document; //Collect all adaptive component family symbols with more than 1 placement point var collector = new FilteredElementCollector(doc); var filter = new ElementClassFilter(typeof(FamilySymbol)); var adaptiveComponents = from fs in collector.WherePasses(filter).Cast <FamilySymbol>() where AdaptiveComponentFamilyUtils.IsAdaptiveComponentFamily(fs.Family) && AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(fs.Family) > 1 select fs; //Display dialog and prompt for selection FormFamilySymbolSelector selector = new FormFamilySymbolSelector(adaptiveComponents); selector.ShowDialog(); //select edge reference Reference hostEdge = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Edge, "Select edge:"); var selectedId = hostEdge.ElementId; Element e = doc.GetElement(selectedId); //get the selected family var selectedFamilySymbol = selector.SelectedElement(); //activate familySymbol selectedFamilySymbol.Activate(); using (TransactionGroup transGroup = new TransactionGroup(doc)) { transGroup.Start("Place Dimensions"); //hack join the element to a wall ElementId wallId = null; if (e is FamilyInstance & JoinGeometryUtils.GetJoinedElements(doc, e).Count < 1) { using (Transaction transaction = new Transaction(doc)) { transaction.Start("Create wall"); //////setup a failure handler to handle any warnings ////FailureHandlingOptions failOpts = transaction.GetFailureHandlingOptions(); ////failOpts.SetFailuresPreprocessor(new WarningSwallower()); ////transaction.SetFailureHandlingOptions(failOpts); wallId = Utils.CreateJoinedWall(doc, wallId, e as FamilyInstance); doc.Regenerate(); transaction.Commit(); } } using (Transaction transaction = new Transaction(doc)) { transaction.Start("Create Family"); //get number of placement point var numberOfPoints = AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(selectedFamilySymbol.Family); double numberOfSpaces = numberOfPoints - 1; //create family var familyInstance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, selectedFamilySymbol); //adjust placment point locations var placementPoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance); for (int i = 0; i < placementPoints.Count; i++) { double interval = i / numberOfSpaces; var location = new PointLocationOnCurve(PointOnCurveMeasurementType.NormalizedCurveParameter, interval, PointOnCurveMeasureFrom.Beginning); var pointOnEdge = doc.Application.Create.NewPointOnEdge(hostEdge, location); var p = doc.GetElement(placementPoints[i]) as ReferencePoint; p.SetPointElementReference(pointOnEdge); } transaction.Commit(); } transGroup.Assimilate(); } return(Result.Succeeded); }
/// <summary> /// 处理碰撞 /// </summary> /// <param name="doc"></param> /// <param name="hostELemID"></param> /// <param name="sd"></param> /// <returns></returns> public static Solid SolidHandle(Document doc, ElementId hostELemID, Solid sd) { //TODO:这里是取得该物体是否剪切别的物体 Element hostElem = doc.GetElement(hostELemID); //碰撞集合 List <Element> elembeCutList = JoinGeometryUtils.GetJoinedElements(doc, hostElem).Where(m => { if (JoinGeometryUtils.AreElementsJoined(doc, doc.GetElement(m), hostElem)) { //if (JoinGeometryUtils.IsCuttingElementInJoin(doc, hostElem, doc.GetElement(m))) //{ return(true); //} } return(false); }).ToList().ConvertAll(m => doc.GetElement(m)); //对于与梁进行碰撞的Solid的处理 if (hostElem.Category.Id == new ElementId(BuiltInCategory.OST_StructuralFraming)) { try { elembeCutList = elembeCutList.Where(m => m.Category .Id == new ElementId(BuiltInCategory.OST_StructuralFraming) || m.Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralColumns).ToList(); } catch { SWF.MessageBox.Show(hostELemID + ""); } } else if (hostElem is Floor) { elembeCutList = elembeCutList.Where(m => m.Category.Id == new ElementId(BuiltInCategory.OST_StructuralFraming) || m.Category.Id == new ElementId(BuiltInCategory.OST_StructuralColumns) || m.Category.Id == new ElementId(BuiltInCategory.OST_Walls)) .ToList(); } else if (hostElem.Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralColumns) { elembeCutList = elembeCutList.Where(m => m is Wall && m.Name.Contains("DW")).ToList(); } else if (hostElem is Wall) { Curve walCurve = (hostElem.Location as LocationCurve).Curve; XYZ startPoint = walCurve.GetEndPoint(0); XYZ endPoint = walCurve.GetEndPoint(1); startPoint = new XYZ(startPoint.X, startPoint.Y, 0); endPoint = new XYZ(endPoint.X, endPoint.Y, 0); List <Element> walElemList = bc.FilterElementList <Wall>(doc).Where(m => { if (hostElem.Id == m.Id) { return(false); } if (!hostElem.Name.Contains("DW")) { return(false); } if (hostElem.LevelId != m.LevelId) { return(false); } Curve mc = (m.Location as LocationCurve).Curve; XYZ sp = mc.GetEndPoint(0); XYZ ep = mc.GetEndPoint(1); sp = new XYZ(sp.X, sp.Y, 0); ep = new XYZ(ep.X, ep.Y, 0); if (sp.IsAlmostEqualTo(startPoint) || sp.IsAlmostEqualTo(endPoint) || ep.IsAlmostEqualTo(endPoint) || ep.IsAlmostEqualTo(startPoint)) { return(true); } return(false); }).ToList(); elembeCutList = elembeCutList.Where(m => m.Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralColumns || (m is Wall && m.Name.Contains("DW"))).ToList(); elembeCutList.AddRange(walElemList); } Solid lastSolid = sd; foreach (Element e in elembeCutList) { Solid sdcut = AllSolid_Of_Element(e)[0]; try { lastSolid = BooleanOperationsUtils.ExecuteBooleanOperation(lastSolid, sdcut, BooleanOperationsType.Difference); }//可能由于几何体太过复杂导致Bool失败 catch { } } return(lastSolid); }
/***************************************************/ /**** 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); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; var acview = doc.ActiveView; var floorTypes = doc.TCollector <FloorType>().ToList(); var selectorUI = FloorTypeSelector.Instance; selectorUI.floortypeBox.ItemsSource = floorTypes; selectorUI.floortypeBox.DisplayMemberPath = "Name"; selectorUI.floortypeBox.SelectedIndex = 0; selectorUI.ShowDialog(); var targetFloortype = selectorUI.floortypeBox.SelectedItem as FloorType; //目标楼板类型 var beamrefs = default(IList <Reference>); try { beamrefs = sel.PickObjects(ObjectType.Element, doc.GetSelectionFilter(m => m.Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralFraming), "选择生成板的梁"); } catch (Exception e) { MessageBox.Show("用户取消了命令!"); return(Result.Cancelled); } var beams = beamrefs.Select(m => m.GetElement(doc)); //var ele = sel.PickObject(ObjectType.Element).GetElement(doc); //var solid = ele.get_Geometry(new Options()).GetSolidOfGeometryObject().First(); //var trans = Transform.Identity; //trans.Origin = new XYZ(-10, 0, 0); //doc.Invoke(m => //{ // var newsolid = SolidUtils.CreateTransformed(solid, trans); // var directshape = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); // directshape.AppendShape(new List<GeometryObject>() {newsolid}); //}, "test"); //doc.Create.NewFloor() Transaction temtran = new Transaction(doc, "temtran"); temtran.Start(); foreach (Element beam in beams) { var joinedelements = JoinGeometryUtils.GetJoinedElements(doc, beam); if (joinedelements.Count > 0) { foreach (var id in joinedelements) { var temele = id.GetElement(doc); var isjoined = JoinGeometryUtils.AreElementsJoined(doc, beam, temele); if (isjoined) { JoinGeometryUtils.UnjoinGeometry(doc, beam, temele); } } } } temtran.RollBack(); var solidss = new List <GeometryObject>();//beams.Select(m => m.Getsolids()); foreach (var element in beams) { solidss.AddRange(element.Getsolids()); } var joinedsolid = MergeSolids(solidss.Cast <Solid>().ToList()); //var upfaces = beams.Select(m => m.get_Geometry(new Options() { DetailLevel = ViewDetailLevel.Fine }).Getupfaces().First()); //MessageBox.Show(upfaces.Count().ToString()); //var solids = upfaces.Select(m => // GeometryCreationUtilities.CreateExtrusionGeometry(m.GetEdgesAsCurveLoops(), XYZ.BasisZ, 10)).ToList(); //MessageBox.Show("solids count" + solids.Count().ToString()); //var targetsolid = MergeSolids(solids); //List<GeometryObject> geoobjs = solids.Cast<GeometryObject>().ToList(); var upfaces = joinedsolid.Getupfaces(); var edgeArrays = upfaces.First().EdgeLoops.Cast <EdgeArray>().ToList(); //var curvearrays = curveloops.Select(); var curveloops = upfaces.First().GetEdgesAsCurveLoops(); var orderedcurveloops = curveloops.OrderBy(m => m.GetExactLength()).ToList(); orderedcurveloops.RemoveAt(orderedcurveloops.Count - 1); curveloops = orderedcurveloops; var curvearrays = curveloops.Select(m => m.ToCurveArray()); doc.Invoke(m => { foreach (var curvearray in curvearrays) { doc.Create.NewFloor(curvearray, false); //doc.Create.NewFloor(curvearray, false); //可指定楼板类型来创建 } }, "一键楼板"); //doc.Invoke(m => //{ // var directshape = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); // //directshape.AppendShape(new List<GeometryObject>(){targetsolid}); // //directshape.AppendShape(solidss); // directshape.AppendShape(new List<GeometryObject>() { joinedsolid }); //}, "temsolid"); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var doc = commandData.Application.ActiveUIDocument.Document; //select element Reference selectedRef = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, "Select element:"); var selectedId = selectedRef.ElementId; Element e = doc.GetElement(selectedId); using (TransactionGroup transGroup = new TransactionGroup(doc)) { transGroup.Start("Place Dimensions"); //hack join the element to a wall ElementId wallId = null; if (e is FamilyInstance & JoinGeometryUtils.GetJoinedElements(doc, e).Count < 1) { using (Transaction transaction = new Transaction(doc)) { transaction.Start("Create wall"); //setup a failure handler to handle any warnings FailureHandlingOptions failOpts = transaction.GetFailureHandlingOptions(); failOpts.SetFailuresPreprocessor(new WarningSwallower()); transaction.SetFailureHandlingOptions(failOpts); wallId = Utils.CreateJoinedWall(doc, wallId, e as FamilyInstance); doc.Regenerate(); transaction.Commit(); } } //because document has been modified, re reference the selected element Element selectedElement = doc.GetElement(selectedId); var solids = new List <Solid>(); //get solids if (selectedElement is FamilyInstance) { //any neseted families? var subxIds = (selectedElement as FamilyInstance).GetSubComponentIds(); if (subxIds.Count > 0) { foreach (var id in subxIds) { var subelement = doc.GetElement(id); solids.AddRange(Utils.GetAllSolidsFromElement(subelement));; } } else { solids.AddRange(Utils.GetAllSolidsFromElement(selectedElement)); } } else { solids.AddRange(Utils.GetAllSolidsFromElement(selectedElement)); } using (Transaction transaction = new Transaction(doc)) { transaction.Start("Create spot elevations"); //get edges from solid foreach (Solid solid in solids) { foreach (Edge edge in solid.Edges) { var reference = edge.GetEndPointReference(0); var point = edge.AsCurve().GetEndPoint(0); var bendPoint = point.Add(XYZ.Zero); var endPoint = point.Add(XYZ.Zero); doc.Create.NewSpotElevation(doc.ActiveView, reference, point, bendPoint, endPoint, point, true); } } transaction.Commit(); } //Clean up, if a wall was created delete it if (wallId != null) { using (Transaction transaction = new Transaction(doc)) { transaction.Start("Delete wall"); doc.Delete(wallId); transaction.Commit(); } } transGroup.Assimilate(); } return(Result.Succeeded); }
public static Result Do(UIApplication uiapp, Dictionary <ElementId, double> level) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; List <XYZ> points = new List <XYZ>(); List <Curve> SplitCurves = new List <Curve>(); List <double> _elevations = RevitModel.LevelElevation.GetElevations(doc); foreach (ElementId e1 in GlobalVariables.SplitObjects) { Curve c1 = Elements.GetCurve(doc, level, e1); if (null != c1) { SplitCurves.Add(c1); foreach (ElementId e2 in GlobalVariables.CutObjects) { Curve c2 = Elements.GetCurve(doc, level, e2); if (null != c2) { XYZ intersection = GetIntersection(c1, c2); if (intersection != null && !PointAlreadyInList.Check(points, intersection)) { points.Add(intersection); } } } } } using (TransactionGroup transgroup = new TransactionGroup(doc, "Intersect Geometry")) { try { if (transgroup.Start() != TransactionStatus.Started) { return(Result.Failed); } foreach (ElementId e1 in GlobalVariables.SplitObjects) { Curve c = Elements.GetCurve(doc, level, e1); FamilyInstance f = Elements.GetFamilyInstance(doc, level, e1); List <Curve> newCurves = ElementSplitter.Do(c, points); ICollection <ElementId> newElements = null; for (int i = 0; i < newCurves.Count; i++) { if (i != 0) // First Element different - just change endpoint // All other make copy first { using (Transaction trans = new Transaction(doc, "Copy element.")) { try { if (trans.Start() != TransactionStatus.Started) { return(Result.Failed); } XYZ transform = newCurves[i].GetEndPoint(0) - c.GetEndPoint(0); newElements = Elements.Transform(doc, e1, transform); if (TransactionStatus.Committed != trans.Commit()) { trans.RollBack(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); trans.RollBack(); } } foreach (ElementId id in newElements) { // Change Curve using (Transaction trans = new Transaction(doc, "Transform element.")) { try { if (trans.Start() != TransactionStatus.Started) { return(Result.Failed); } FamilyInstance newf = Elements.GetFamilyInstance(doc, level, id); Elements.ChangeEndPoint(doc, newCurves[i], newf, level, _elevations); FailureHandlingOptions options = trans.GetFailureHandlingOptions(); options.SetFailuresPreprocessor(new WarningSwallower()); if (TransactionStatus.Committed != trans.Commit(options)) { trans.RollBack(); } } catch { trans.RollBack(); } } } } else { using (Transaction trans = new Transaction(doc, "Transform element.")) { try { if (trans.Start() != TransactionStatus.Started) { return(Result.Failed); } foreach (ElementId eId in JoinGeometryUtils.GetJoinedElements(doc, f)) { JoinGeometryUtils.UnjoinGeometry(doc, doc.GetElement(e1), doc.GetElement(eId)); } FailureHandlingOptions options = trans.GetFailureHandlingOptions(); options.SetFailuresPreprocessor(new WarningSwallower()); if (TransactionStatus.Committed != trans.Commit(options)) { trans.RollBack(); } } catch { trans.RollBack(); } } using (Transaction trans = new Transaction(doc, "Transform element.")) { try { if (trans.Start() != TransactionStatus.Started) { return(Result.Failed); } LocationCurve orig_location = f.Location as LocationCurve; double orig_len = orig_location.Curve.Length; double up_len = newCurves[i].Length; Elements.ChangeEndPoint(doc, newCurves[i], f, level, _elevations); LocationCurve after_location = f.Location as LocationCurve; double after_len = after_location.Curve.Length; doc.Regenerate(); LocationCurve regen_location = f.Location as LocationCurve; double regen_len = regen_location.Curve.Length; uidoc.RefreshActiveView(); FailureHandlingOptions options = trans.GetFailureHandlingOptions(); options.SetFailuresPreprocessor(new WarningSwallower()); options.SetClearAfterRollback(true); if (TransactionStatus.Committed != trans.Commit(options)) { trans.RollBack(); return(Result.Failed); } } catch { trans.RollBack(); return(Result.Failed); } } } } } if (transgroup.Assimilate() == TransactionStatus.Committed) { return(Result.Succeeded); } else { return(Result.Failed); } } catch { transgroup.RollBack(); return(Result.Failed); } } }