protected override Result ProcessCommand(ExternalCommandData commandData, ref string message, ElementSet elements) { Reference r = _activeUIDocument.Selection.PickObject(ObjectType.Element); var element = _activeDocument.GetElement(r.ElementId); var boundingBox = element.get_BoundingBox(_activeDocument.ActiveView); var outLine = new Outline(boundingBox.Min, boundingBox.Max); var bbFilter = new BoundingBoxIntersectsFilter(outLine); FilteredElementCollector collector = new FilteredElementCollector(_activeDocument, _activeDocument.ActiveView.Id); ICollection <ElementId> idsExclude = new List <ElementId>(); idsExclude.Add(element.Id); collector.Excluding(idsExclude).WherePasses(bbFilter); int nCount = 0; string report = string.Empty; foreach (Element e in collector) { string name = e.Name; report += "\nName = " + name + " Element Id: " + e.Id.ToString(); nCount++; } TaskDialog.Show( "Bounding Box + View + Exclusion Filter", "Found " + nCount.ToString() + " elements whose bounding box intersects" + report); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Transaction trans = new Transaction(doc, "ExComm"); trans.Start(); Selection select = uidoc.Selection; Reference r = select.PickObject(ObjectType.Element, "选择需要检查的墙"); Element column = doc.GetElement(r); FilteredElementCollector collect = new FilteredElementCollector(doc); //ElementIntersectFilter冲突检查 ElementIntersectsElementFilter iFilter = new ElementIntersectsElementFilter(column, false); collect.WherePasses(iFilter); List <ElementId> excludes = new List <ElementId>(); excludes.Add(column.Id); collect.Excluding(excludes); List <ElementId> ids = new List <ElementId>(); select.SetElementIds(ids); foreach (Element elem in collect) { ids.Add(elem.Id); } select.SetElementIds(ids); trans.Commit(); return(Result.Succeeded); }
public static ICollection <ElementId> GetUnusedTextNoteTypes(Document doc) { FilteredElementCollector unusedTypeCollector = new FilteredElementCollector(doc) .OfClass(typeof(TextNoteType)); // if there are USED Text Notes exclude the from the collector if (0 < Helpers.GetUsedTextNoteTypes(doc).Count) { unusedTypeCollector.Excluding(Helpers.GetUsedTextNoteTypes(doc)); // sort list by Name List <ElementId> sortedlist = unusedTypeCollector.ToElementIds().ToList(); sortedlist = sortedlist.OrderBy(i => doc.GetElement(i).Name).ToList(); return(sortedlist); } // otherwise return the whole list from the collector else { List <ElementId> sortedlist = unusedTypeCollector.ToElementIds().ToList(); sortedlist = sortedlist.OrderBy(i => doc.GetElement(i).Name).ToList(); return(sortedlist); //return unusedTypeCollector.ToElementIds(); } }
//---------------------------------------------------------- public static List <Element> intersection_framing(Document doc, Element element) { List <Element> elements = new List <Element>(); try { BoundingBoxXYZ bb = element.get_BoundingBox(doc.ActiveView); Outline outline = new Outline(bb.Min, bb.Max); BoundingBoxIntersectsFilter bbfilter = new BoundingBoxIntersectsFilter(outline); FilteredElementCollector collectors = new FilteredElementCollector(doc, doc.ActiveView.Id); ICollection <ElementId> idsExclude = new List <ElementId>(); idsExclude.Add(element.Id); var collector = collectors.Excluding(idsExclude).WherePasses(bbfilter).ToElements(); foreach (Element ele in collector) { if (ele.LookupParameter("Name") != null && ele.LookupParameter("LevelPart") != null) { if (ele.Category.Name != "Structural Framing" && ele.Category.Name != "Floors") { elements.Add(ele); } } } } catch (Exception) { } return(elements); }
/// <summary> 找到与某Element的几何实体相交的Elements </summary> public void FindIntersectWallsByElement() { Transaction trans = new Transaction(Doc, "ExComm"); trans.Start(); // 选择一个柱子 Selection sel = UIDoc.Selection; Reference ref1 = sel.PickObject(ObjectType.Element, "Please pick a column"); Element column = Doc.GetElement(ref1); // 应用过滤器,在整个文档中搜索与指定Element相交的Element FilteredElementCollector collector = new FilteredElementCollector(Doc); ElementIntersectsElementFilter elementFilter = new ElementIntersectsElementFilter(column, false); collector.WherePasses(elementFilter); // 排除柱子本身 List <ElementId> excludes = new List <ElementId>(); excludes.Add(column.Id); collector.Excluding(excludes); //将最终的相交结果选中 List <ElementId> selEle = new List <ElementId>(); foreach (Element elem in collector) { selEle.Add(elem.Id); } sel.SetElementIds(selEle); trans.Commit(); }
GetUnusedTextNoteTypesExcluding( Document doc) { ICollection <ElementId> usedTextNotesTypeIds = new Collection <ElementId>(); FilteredElementCollector textNotes = new FilteredElementCollector(doc) .OfClass(typeof(TextNote)); foreach (TextNote textNote in textNotes) { usedTextNotesTypeIds.Add( textNote.TextNoteType.Id); } FilteredElementCollector unusedTypeCollector = new FilteredElementCollector(doc) .OfClass(typeof(TextNoteType)); if (0 < usedTextNotesTypeIds.Count) { unusedTypeCollector.Excluding( usedTextNotesTypeIds); } ICollection <ElementId> unusedTypes = unusedTypeCollector.ToElementIds(); return(unusedTypes); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var uiDoc = uiApp.ActiveUIDocument; var app = uiApp.Application; var doc = uiDoc.Document; try { var refObject = uiDoc.Selection.PickObject(ObjectType.Element); var elementId = refObject.ElementId; var element = doc.GetElement(elementId); //var elementTypeId = element.GetTypeId(); var elementType = element.GetType(); // option để lọc ra geometry trên element // Két quả Geometry trả về tùy thuộc vào thiết lập trong option này var option = new Options(); option.DetailLevel = ViewDetailLevel.Fine; option.ComputeReferences = true; // Lấy ra các đối tượng Solid trong element GetElementGeometry(element, option, out var curvers, out var solids); ICollection <ElementId> idsExclude = new List <ElementId>(); idsExclude.Add(element.Id); var collector = new FilteredElementCollector(doc); var listFilter = new List <ElementFilter>(); foreach (var solid in solids) { var intersectFilter = new ElementIntersectsSolidFilter(solid); listFilter.Add(intersectFilter); } var logicFilter = new LogicalOrFilter(listFilter); //var faces = solids[0].Faces.Cast<Face>().ToList(); //var edge = solids[0].Edges.Cast<Edge>().ToList(); //var points = edge[0].Tessellate(); //var faceArea = faces[0].Area; var intersections = collector .Excluding(idsExclude) //.OfClass(typeof(FamilyInstance)) .WherePasses(logicFilter) .ToElementIds(); uiDoc.Selection.SetElementIds(intersections); } catch (Exception e) { message = e.Message; return(Result.Failed); } return(Result.Succeeded); }
/// <summary> /// 判断当前创建出来的那个实体是否与其他单元相交,如果相交,则在原实体中剪除相交的部分,如果没有相交,则直接返回原实体集合(集合中的元素个数与原 originalSolids 集合中元素个数相同)。 /// </summary> /// <param name="directShape"></param> /// <param name="originalSolids"> directShape 所对应的实体,由于 ExecuteBooleanOperationModifyingOriginalSolid 函数中的 OriginalSolid /// 不能是直接从Revit的Element中得到的,所以要将前面通过轮廓拉伸出来的实体作为参数传入。</param> /// <param name="hasIntersect"></param>剪切后的实体的体积有可能不大于 0 啊 /// <returns> 返回的集合中的元素个数与原 originalSolids 集合中元素个数相同。剪切后的实体的体积有可能不大于 0 .</returns> private IList <Solid> ExcludeIntersect(DirectShape directShape, IList <Solid> originalSolids, out bool hasIntersect) { // 应用过滤器,在整个文档中搜索与指定Element相交的Element FilteredElementCollector collector = new FilteredElementCollector(directShape.Document); ElementIntersectsElementFilter elementFilter = new ElementIntersectsElementFilter(element: directShape, inverted: false); collector.WherePasses(elementFilter); // 排除面层本身 collector.Excluding(new ElementId[] { directShape.Id }); if (!collector.Any()) { // 说明没有相交的部分 hasIntersect = false; return(originalSolids); } hasIntersect = true; // 将与其相交的实体进行剪切操作 bool promptWhileError = false; foreach (Element interSectElem in collector) { var interSectSolids = GeoHelper.GetSolidsInModel(interSectElem, GeoHelper.SolidVolumnConstraint.Positive).Keys; // 与面层对象相交的 Element 中所有的实体 for (int i = 0; i < originalSolids.Count; i++) { Solid originalS = originalSolids[i]; foreach (Solid interSectS in interSectSolids) { try { // 在原实体中减去相交的部分 BooleanOperationsUtils.ExecuteBooleanOperationModifyingOriginalSolid(originalS, interSectS, BooleanOperationsType.Difference); } catch (Exception ex) { if (promptWhileError) { // 在剪切时如果不能剪切,则不剪切。 DialogResult res = MessageBox.Show("实体剪切时出现错误,可能的原因是面层与模型中的其他实体有细微交叉," + "以致剪切后的实体出现细小锯齿。\n\r (忽略此细微交叉对于面层算量并无明显影响)。" + " \n\r 点击“是”以忽略并继续,点击“否”不再提示。", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button2); promptWhileError = (res != DialogResult.No); } } } // 剪切后的实体的体积有可能不大于 0 啊 originalSolids[i] = originalS; // 将剪切完成后的 Solid 再赋值回集合中 } } return(originalSolids); }
private static int DuplicateDetailingAcrossViews(View fromView, View toView) { int numberOfCopiedElements = 0; try { List <ElementId> elementIdsToExclude = new List <ElementId>(); ICollection <ElementId> referenceCalloutIds = fromView.GetReferenceCallouts(); elementIdsToExclude.AddRange(referenceCalloutIds); ICollection <ElementId> referenceElevationIds = fromView.GetReferenceElevations(); elementIdsToExclude.AddRange(referenceElevationIds); ICollection <ElementId> referenceSectionIds = fromView.GetReferenceSections(); elementIdsToExclude.AddRange(referenceSectionIds); FilteredElementCollector collector = new FilteredElementCollector(fromView.Document, fromView.Id); if (elementIdsToExclude.Count > 0) { collector.Excluding(elementIdsToExclude); } collector.WherePasses(new ElementCategoryFilter(ElementId.InvalidElementId, true)); ICollection <ElementId> toCopy = collector.ToElementIds(); CopyPasteOptions options = new CopyPasteOptions(); options.SetDuplicateTypeNamesHandler(new HideAndAcceptDuplicateTypeNamesHandler()); if (toCopy.Count > 0) { using (Transaction t2 = new Transaction(toView.Document, "Duplicate view detailing")) { t2.Start(); try { ICollection <ElementId> copiedElements = ElementTransformUtils.CopyElements(fromView, toCopy, toView, Transform.Identity, options); numberOfCopiedElements = copiedElements.Count; FailureHandlingOptions failureOptions = t2.GetFailureHandlingOptions(); failureOptions.SetFailuresPreprocessor(new HidePasteDuplicateTypesPreprocessor()); t2.Commit(failureOptions); } catch (Exception ex) { string message = ex.Message; t2.RollBack(); } } } } catch (Exception ex) { //MessageBox.Show("Failed to duplicate detialing across views.\n"+ex.Message, "Duplicate Detailing Across Views", MessageBoxButton.OK, MessageBoxImage.Warning); errorMessage.AppendLine(toView.Name + ": errors in duplicating detailing across views.\n" + ex.Message); } return(numberOfCopiedElements); }
/// <summary> /// Merge <paramref name="boundingBoxXyz"/> with the 'BoundingBoxXYZ's of /// all 'GenericForm's in <paramref name="document"/> that are solid into /// a new 'BoundingBoxXYZ'. /// Exclude all 'GenericForm's in /// <paramref name="genericFormExclusionSet"/> from being found in /// <paramref name="document"/>. /// </summary> /// <param name="document">The Revit 'Document' to search for all /// 'GenericForm's excluding the ones in /// <paramref name="genericFormExclusionSet"/>.</param> /// <param name="boundingBoxXyz">The 'BoundingBoxXYZ' to merge with.</param> /// <param name="genericFormExclusionSet">A 'HashSet' of all the /// 'GenericForm's to exclude from being merged with in /// <paramref name="document"/>.</param> /// <returns>The new merged 'BoundingBoxXYZ' of /// <paramref name="boundingBoxXyz"/> and all 'GenericForm's excluding /// the ones in <paramref name="genericFormExclusionSet"/> /// in <paramref name="document"/></returns> private static BoundingBoxXYZ MergeSolidBoundingBoxXyz( Document document, BoundingBoxXYZ boundingBoxXyz, ISet <ElementId> genericFormExclusionSet) { BoundingBoxXYZ mergedResult = boundingBoxXyz; FilteredElementCollector genericFormCollector = new FilteredElementCollector(document) .OfClass(typeof(GenericForm)); if (genericFormExclusionSet != null && genericFormExclusionSet.Any()) { genericFormCollector.Excluding( genericFormExclusionSet); } foreach (GenericForm solid in genericFormCollector .Cast <GenericForm>() .Where(genericForm => genericForm.IsSolid)) { BoundingBoxXYZ solidBoundingBox = solid.get_BoundingBox(null); if (solidBoundingBox == null) { continue; } if (mergedResult == null) { mergedResult = new BoundingBoxXYZ(); mergedResult.Min = solidBoundingBox.Min; mergedResult.Max = solidBoundingBox.Max; continue; } mergedResult = MergeBoundingBoxXyz( mergedResult, solidBoundingBox); } return(mergedResult); }
/// <summary> /// Get the view crop element and crop region curves /// </summary> /// <param name="view"></param> /// <returns></returns> internal static ViewCrop GetViewCrop(Autodesk.Revit.DB.View view) { var doc = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(doc); ViewCrop viewCrop; using (SubTransaction tGroup = new SubTransaction(doc)) { tGroup.Start(); using (SubTransaction t1 = new SubTransaction(doc)) { // Deactivate crop box t1.Start(); view.CropBoxVisible = false; t1.Commit(); doc.Regenerate(); // Get all visible elements, which does not include the crop box FilteredElementCollector collector = new FilteredElementCollector(doc, view.Id); ICollection <ElementId> shownElems = collector.ToElementIds(); // Activate the crop box t1.Start(); view.CropBoxVisible = true; t1.Commit(); doc.Regenerate(); // Get all visible elements, excluding everything but the crop box collector = new FilteredElementCollector(doc, view.Id); collector.Excluding(shownElems); viewCrop.cropElement = collector.FirstElement(); viewCrop.cropRegion = view.GetCropRegionShapeManager().GetCropShape().First(); } tGroup.RollBack(); } TransactionManager.Instance.TransactionTaskDone(); return(viewCrop); }
/// <summary> /// This node will attempt to rotate a plan view into a 3D view. Use at your own risk! /// </summary> /// <param name="viewPlan">The plan view to rotate</param> /// <param name="rotationLine">The line to rotate along.</param> /// <param name="inputAngle">The plan view to get outline from.</param> /// <returns name="cropBox">The cropBox.</returns> /// <search> /// view, outline,rhythm /// </search> public static object Rotate(global::Revit.Elements.Element viewPlan, global::Revit.Elements.ModelCurve rotationLine, double inputAngle) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.View internalView = (Autodesk.Revit.DB.View)viewPlan.InternalElement; var viewBbox = internalView.CropBox; Autodesk.Revit.DB.ModelCurve internalLine = (Autodesk.Revit.DB.ModelCurve)rotationLine.InternalElement; Autodesk.Revit.DB.Line rotationLineBound = Autodesk.Revit.DB.Line.CreateBound(internalLine.GeometryCurve.GetEndPoint(0), internalLine.GeometryCurve.GetEndPoint(1)); Autodesk.Revit.DB.Element cropBoxElement = null; using (TransactionGroup tGroup = new TransactionGroup(doc)) { tGroup.Start("Temp to find crop box element"); using (Transaction t2 = new Transaction(doc, "Temp to find crop box element")) { // Deactivate crop box t2.Start(); internalView.CropBoxVisible = false; t2.Commit(); // Get all visible elements; // this excludes hidden crop box FilteredElementCollector collector = new FilteredElementCollector(doc, internalView.Id); ICollection <ElementId> shownElems = collector.ToElementIds(); // Activate crop box t2.Start(); internalView.CropBoxVisible = true; t2.Commit(); // Get all visible elements excluding // everything except the crop box collector = new FilteredElementCollector(doc, internalView.Id); collector.Excluding(shownElems); cropBoxElement = collector.FirstElement(); } tGroup.RollBack(); } TransactionManager.Instance.EnsureInTransaction(doc); ElementTransformUtils.RotateElement(doc, cropBoxElement.Id, rotationLineBound, inputAngle); TransactionManager.Instance.TransactionTaskDone(); return(cropBoxElement); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; Transaction tran = new Transaction(doc, "ExCom"); tran.Start(); Selection select = uiDoc.Selection; Reference r = select.PickObject(ObjectType.Element, "选择需要检查的墙"); Element column = doc.GetElement(r); FilteredElementCollector collector = new FilteredElementCollector(doc); //使用ElementIntersectFilter冲突检查 ElementIntersectsElementFilter iFilter = new ElementIntersectsElementFilter(column, false); collector.WherePasses(iFilter); List <ElementId> excludes = new List <ElementId> { column.Id }; collector.Excluding(excludes); List <ElementId> ids = new List <ElementId>(); select.SetElementIds(ids); foreach (Element element in collector) { ids.Add(element.Id); } select.SetElementIds(ids); tran.Commit(); CurveLoop curs = null; ElementId rId = null; ElementId leveId = null; Railing rail = Railing.Create(doc, curs, rId, leveId); return(Result.Succeeded); }
//---------------------------------------------------------- public void Join_Element(Document doc, Element element) { try { BoundingBoxXYZ bb = element.get_BoundingBox(doc.ActiveView); Outline outline = new Outline(bb.Min, bb.Max); BoundingBoxIntersectsFilter bbfilter = new BoundingBoxIntersectsFilter(outline); FilteredElementCollector collectors = new FilteredElementCollector(doc, doc.ActiveView.Id); ICollection <ElementId> idsExclude = new List <ElementId>(); idsExclude.Add(element.Id); var collector = collectors.Excluding(idsExclude).WherePasses(bbfilter).ToElements(); foreach (Element ele in collector) { if (JoinGeometryUtils.AreElementsJoined(doc, element, ele) == false && ele.Category.AllowsBoundParameters == true && ele.Category.CategoryType.ToString() == "Model") { JoinGeometryUtils.JoinGeometry(doc, element, ele); } } } catch (Exception ex) { //MessageBox.Show(ex.Message); } }
/// <summary> /// Find walls (nearly joined to) end of walls /// </summary> /// <param name="walls">The walls to be detected</param> /// <returns>The detection result</returns> public XElement findNearbyWalls(IEnumerable <Wall> walls) { // create a node that place all walls. XElement wallsNode = new XElement("Walls", new XAttribute("Name", "Walls")); try { foreach (Wall wall in walls) { XElement wallNode = new XElement("Wall", new XAttribute("Name", wall.Name)); // Start XElement endNode = new XElement("Start", new XAttribute("Name", "Start")); XYZ wallEndPoint = (wall.Location as LocationCurve).Curve.GetEndPoint(0); double wallHeight = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble(); FilteredElementCollector collector = nearbyWallsFilter(wallEndPoint, wallHeight, 10.0); // 10 ft // Exclude the wall itself List <ElementId> exclusions = new List <ElementId>(); exclusions.Add(wall.Id); collector.Excluding(exclusions); IEnumerable <Wall> nearbyWalls = collector.OfType <Wall>(); XElement nearbyWallsNode = new XElement("near_by_walls", new XAttribute("Count", nearbyWalls.Count().ToString())); foreach (Wall nearbywall in nearbyWalls) { nearbyWallsNode.Add(new XElement("near_by_wall", new XAttribute("Name", nearbywall.Name))); } endNode.Add(nearbyWallsNode); wallNode.Add(endNode); // End endNode = new XElement("End", new XAttribute("Name", "End")); wallEndPoint = (wall.Location as LocationCurve).Curve.GetEndPoint(1); collector = nearbyWallsFilter(wallEndPoint, wallHeight, 10.0); // Exclude the wall itself exclusions = new List <ElementId>(); exclusions.Add(wall.Id); collector.Excluding(exclusions); nearbyWalls = collector.OfType <Wall>(); nearbyWallsNode = new XElement("near_by_walls", new XAttribute("Count", nearbyWalls.Count().ToString())); foreach (Wall nearbywall in nearbyWalls) { nearbyWallsNode.Add(new XElement("near_by_wall", new XAttribute("Name", nearbywall.Name))); } endNode.Add(nearbyWallsNode); wallNode.Add(endNode); wallsNode.Add(wallNode); } } catch (Exception ex) { wallsNode.Add(new XElement("Error", new XAttribute("Exception", ex.ToString()))); } // return the whole walls Node return(wallsNode); }
public void TransferViewproject(Document source, Document targets, ICollection <ElementId> elementIds, string Title_name, int versionnumber) { Transaction newtran = new Transaction(targets, "Transfer"); newtran.Start(); CopyPasteOptions options = new CopyPasteOptions(); options.SetDuplicateTypeNamesHandler(new CopyHandler()); foreach (var i in elementIds) { View view = source.GetElement(i) as View; if (view.ViewType == ViewType.Legend) { IList <ElementId> list1 = (from View i1 in new FilteredElementCollector(targets).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.ViewType == ViewType.Legend select i1.Id).ToList(); ICollection <ElementId> collection2 = new List <ElementId>(); collection2.Add(i); ICollection <ElementId> litstrans = ElementTransformUtils.CopyElements(source, collection2, targets, null, options); foreach (var m in litstrans) { View o = targets.GetElement(m) as View; o.Name = o.Name + "(" + Title_name + ")"; } if (versionnumber <= 2019) { View val4 = (from View i1 in new FilteredElementCollector(source).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.Id == i select i1).FirstOrDefault(); FilteredElementCollector val5 = new FilteredElementCollector(targets).OfClass(typeof(View)); if (list1.Count > 0) { var Y = val5.Excluding(list1); } View val6 = (from View i1 in val5.WhereElementIsNotElementType() where (int)i1.ViewType == 11 select i1).FirstOrDefault(); ElementOwnerViewFilter val7 = new ElementOwnerViewFilter(val4.Id); ElementCategoryFilter val8 = new ElementCategoryFilter(BuiltInCategory.OST_IOSSketchGrid, true); ElementCategoryFilter val9 = new ElementCategoryFilter(BuiltInCategory.OST_CLines, true); FilteredElementCollector val10 = new FilteredElementCollector(source); val10.WherePasses(val7); val10.WherePasses(val8); val10.WherePasses(val9); IList <ElementId> list2 = (from Element i1 in val10 where i1.Category != null select i1.Id).ToList(); if (list2.Count > 0) { ElementTransformUtils.CopyElements(val4, list2, val6, null, options); } } } if (view.ViewType == ViewType.DraftingView) { IList <ElementId> list1 = (from View i1 in new FilteredElementCollector(targets).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.ViewType == ViewType.DraftingView select i1.Id).ToList(); ICollection <ElementId> collection2 = new List <ElementId>(); collection2.Add(i); ICollection <ElementId> litstrans = ElementTransformUtils.CopyElements(source, collection2, targets, null, options); foreach (var m in litstrans) { View o = targets.GetElement(m) as View; o.Name = o.Name + "(" + Title_name + ")"; } View val4 = (from View i1 in new FilteredElementCollector(source).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.Id == i select i1).FirstOrDefault(); FilteredElementCollector val5 = new FilteredElementCollector(targets).OfClass(typeof(View)); if (list1.Count > 0) { var Y = val5.Excluding(list1); } View val6 = (from View i1 in val5.WhereElementIsNotElementType() where i1.ViewType == ViewType.DraftingView select i1).FirstOrDefault(); ElementOwnerViewFilter val7 = new ElementOwnerViewFilter(val4.Id); ElementCategoryFilter val8 = new ElementCategoryFilter(BuiltInCategory.OST_IOSSketchGrid, true); ElementCategoryFilter val9 = new ElementCategoryFilter(BuiltInCategory.OST_CLines, true); FilteredElementCollector val10 = new FilteredElementCollector(source); val10.WherePasses(val7); val10.WherePasses(val8); val10.WherePasses(val9); IList <ElementId> list2 = (from Element i1 in val10 where i1.Category != null select i1.Id).ToList(); IList <ElementId> list3 = new List <ElementId>(); foreach (var u in list2) { Element po = source.GetElement(u); var ty = po.Category.Name.ToString(); if (ty != "Views") { list3.Add(u); } } if (list3.Count > 0) { ElementTransformUtils.CopyElements(val4, list3, val6, null, options); } } if (view.ViewType == ViewType.Schedule) { IList <ElementId> list1 = (from View i1 in new FilteredElementCollector(targets).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.ViewType == ViewType.Schedule select i1.Id).ToList(); ICollection <ElementId> collection2 = new List <ElementId>(); collection2.Add(i); ICollection <ElementId> litstrans = ElementTransformUtils.CopyElements(source, collection2, targets, null, options); foreach (var m in litstrans) { View o = targets.GetElement(m) as View; o.Name = o.Name + "(" + Title_name + ")"; } } } newtran.Commit(); }
/// <summary> /// Find elements blocking egress /// </summary> /// <param name="egresses">The egresses to be detected</param> /// <returns>The detection result</returns> public XElement findBlockingElements(ICollection <Element> egresses) { // create a node that place all egresses. XElement egressesNode = new XElement("Egresses", new XAttribute("Name", "Egresses")); try { // find the elements blocking egress foreach (Element egressElement in egresses) { XElement egressNode = new XElement("Egress", new XAttribute("Name", egressElement.Name)); int count = 1; IEnumerator <GeometryObject> Objects = egressElement.get_Geometry(new Autodesk.Revit.DB.Options()).GetEnumerator(); Objects.MoveNext(); GeometryInstance gi = Objects.Current as GeometryInstance; IEnumerator <GeometryObject> Objects1 = gi.GetInstanceGeometry().GetEnumerator(); //foreach (GeometryObject egressGObj in // (egressElement.get_Geometry(new Autodesk.Revit.DB.Options()).Objects.get_Item(0) as GeometryInstance).GetInstanceGeometry().Objects) while (Objects1.MoveNext()) { GeometryObject egressGObj = Objects1.Current; if (egressGObj is Solid) { Solid egressVolume = egressGObj as Solid; //calculated from shape and location of a given door XElement solidNode = new XElement("ElementSolid" + count.ToString()); // Iterate to find all instance types FilteredElementCollector blockingcollector = new FilteredElementCollector(m_doc); blockingcollector.WhereElementIsNotElementType(); // Apply geometric filter ElementIntersectsSolidFilter testElementIntersectsSolidFilter = new ElementIntersectsSolidFilter(egressVolume); blockingcollector.WherePasses(testElementIntersectsSolidFilter); IEnumerable <Element> blockingElement = blockingcollector; // Exclude the door itself List <ElementId> exclusions = new List <ElementId>(); exclusions.Add(egressElement.Id); blockingcollector.Excluding(exclusions); XElement blockingegressNode = new XElement("blocking_egress_elements", new XAttribute("Count", blockingElement.Count().ToString())); foreach (Element blockingelement in blockingElement) { blockingegressNode.Add(new XElement("blocking_egress_element", new XAttribute("Name", blockingelement.Name))); } solidNode.Add(blockingegressNode); egressNode.Add(solidNode); count++; } } egressesNode.Add(egressNode); } } catch (Exception ex) { egressesNode.Add(new XElement("Error", new XAttribute("Exception", ex.ToString()))); } // return the whole Egresses Node return(egressesNode); }
/// <summary> /// Find elements blocking egress /// </summary> /// <param name="egresses">The egresses to be detected</param> /// <returns>The detection result</returns> public XElement findBlockingElements(ICollection<Element> egresses) { // create a node that place all egresses. XElement egressesNode = new XElement("Egresses", new XAttribute("Name", "Egresses")); try { // find the elements blocking egress foreach (Element egressElement in egresses) { XElement egressNode = new XElement("Egress", new XAttribute("Name", egressElement.Name)); int count = 1; foreach (GeometryObject egressGObj in (egressElement.get_Geometry(new Autodesk.Revit.DB.Options()).Objects.get_Item(0) as GeometryInstance).GetInstanceGeometry().Objects) { if (egressGObj is Solid) { Solid egressVolume = egressGObj as Solid; //calculated from shape and location of a given door XElement solidNode = new XElement("ElementSolid" + count.ToString()); // Iterate to find all instance types FilteredElementCollector blockingcollector = new FilteredElementCollector(m_doc); blockingcollector.WhereElementIsNotElementType(); // Apply geometric filter ElementIntersectsSolidFilter testElementIntersectsSolidFilter = new ElementIntersectsSolidFilter(egressVolume); blockingcollector.WherePasses(testElementIntersectsSolidFilter); IEnumerable<Element> blockingElement = blockingcollector; // Exclude the door itself List<ElementId> exclusions = new List<ElementId>(); exclusions.Add(egressElement.Id); blockingcollector.Excluding(exclusions); XElement blockingegressNode = new XElement("blocking_egress_elements", new XAttribute("Count", blockingElement.Count().ToString())); foreach (Element blockingelement in blockingElement) { blockingegressNode.Add(new XElement("blocking_egress_element", new XAttribute("Name", blockingelement.Name))); } solidNode.Add(blockingegressNode); egressNode.Add(solidNode); count++; } } egressesNode.Add(egressNode); } } catch (Exception ex) { egressesNode.Add(new XElement("Error", new XAttribute("Exception", ex.ToString()))); } // return the whole Egresses Node return egressesNode; }
/// <summary> /// Return all unused text note types by first /// determining all text note types in use and /// then collecting all the others using an /// exclusion filter. /// </summary> ICollection<ElementId> GetUnusedTextNoteTypesExcluding( Document doc) { ICollection<ElementId> usedTextNotesTypeIds = new Collection<ElementId>(); FilteredElementCollector textNotes = new FilteredElementCollector( doc ) .OfClass( typeof( TextNote ) ); foreach( TextNote textNote in textNotes ) { usedTextNotesTypeIds.Add( textNote.TextNoteType.Id ); } FilteredElementCollector unusedTypeCollector = new FilteredElementCollector( doc ) .OfClass( typeof( TextNoteType ) ); if( 0 < usedTextNotesTypeIds.Count ) { unusedTypeCollector.Excluding( usedTextNotesTypeIds ); } ICollection<ElementId> unusedTypes = unusedTypeCollector.ToElementIds(); return unusedTypes; }
/// <summary> /// /// </summary> /// <param name="category"></param> /// <param name="refresh"></param> /// <returns></returns> public static List <List <Autodesk.DesignScript.Geometry.Point> > IntersectionPointsByCategory(Revit.Elements.Category category, Document document = null, bool refresh = false) { List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>(); List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >(); List <List <Autodesk.DesignScript.Geometry.Point> > cPoints = new List <List <Autodesk.DesignScript.Geometry.Point> >(); if (refresh) { BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true); Document doc = DocumentManager.Instance.CurrentDBDocument; //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication; //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument; ElementCategoryFilter filter = new ElementCategoryFilter(myCatEnum); ElementCategoryFilter exclude = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel); FilteredElementCollector excluded = new FilteredElementCollector(doc).WherePasses(exclude); FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType(); collector.Excluding(excluded.ToElementIds()); foreach (Autodesk.Revit.DB.Element e in collector) { DynaFunctions f = new DynaFunctions(); ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e); FilteredElementCollector interElem = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType(); if (interElem.GetElementCount() > 0) { List <Autodesk.Revit.DB.Solid> elGeoms = new List <Autodesk.Revit.DB.Solid>(); GeometryElement geomEl = e.get_Geometry(new Options()); foreach (GeometryObject geomObj in geomEl) { elGeoms.Add(geomObj as Autodesk.Revit.DB.Solid); } elList.Add(doc.GetElement(e.Id).ToDSType(true)); List <Autodesk.Revit.DB.Solid> iS = new List <Autodesk.Revit.DB.Solid>(); List <Autodesk.DesignScript.Geometry.Point> cPoint = new List <Autodesk.DesignScript.Geometry.Point>(); List <Autodesk.DesignScript.Geometry.Solid> iSS = new List <Autodesk.DesignScript.Geometry.Solid>(); foreach (Autodesk.Revit.DB.Element el in interElem) { GeometryElement intEl = el.get_Geometry(new Options()); foreach (GeometryObject intObj in intEl) { iS.Add(intObj as Autodesk.Revit.DB.Solid); } } foreach (Autodesk.Revit.DB.Solid s0 in elGeoms) { foreach (Autodesk.Revit.DB.Solid s1 in iS) { Autodesk.Revit.DB.Solid i = BooleanOperationsUtils.ExecuteBooleanOperation(s0, s1, BooleanOperationsType.Intersect); if (i != null) { iSS.Add(Revit.GeometryConversion.RevitToProtoSolid.ToProtoType(i)); DisplayUnitType dt = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits; XYZ coord = new XYZ(f.convertToUnit(i.ComputeCentroid().X, dt), f.convertToUnit(i.ComputeCentroid().Y, dt), f.convertToUnit(i.ComputeCentroid().Z, dt)); //XYZ coord = new XYZ(i.ComputeCentroid().X, i.ComputeCentroid().Y, i.ComputeCentroid().Z); Autodesk.DesignScript.Geometry.Point p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(coord.X, coord.Y, coord.Z); cPoint.Add(p); } } } cPoints.Add(cPoint); } } } return(cPoints); }
/// <summary> /// /// </summary> /// <param name="category"></param> /// <param name="refresh"></param> /// <returns></returns> public static List <List <Autodesk.DesignScript.Geometry.Solid> > IntersectionSolidsByCategory(Revit.Elements.Category category, Document document = null, bool refresh = false) { List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>(); List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >(); List <List <Autodesk.DesignScript.Geometry.Solid> > interGeoms = new List <List <Autodesk.DesignScript.Geometry.Solid> >(); if (refresh) { BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true); Document doc = DocumentManager.Instance.CurrentDBDocument; //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication; //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument; ElementCategoryFilter filter = new ElementCategoryFilter(myCatEnum); ElementCategoryFilter exclude = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel); FilteredElementCollector excluded = new FilteredElementCollector(doc).WherePasses(exclude); FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType(); collector.Excluding(excluded.ToElementIds()); foreach (Autodesk.Revit.DB.Element e in collector) { DynaFunctions f = new DynaFunctions(); ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e); FilteredElementCollector interElem = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType(); if (interElem.GetElementCount() > 0) { List <Autodesk.Revit.DB.Solid> elGeoms = new List <Autodesk.Revit.DB.Solid>(); GeometryElement geomEl = e.get_Geometry(new Options()); foreach (GeometryObject geomObj in geomEl) { elGeoms.Add(geomObj as Autodesk.Revit.DB.Solid); } List <Autodesk.Revit.DB.Solid> iS = new List <Autodesk.Revit.DB.Solid>(); List <Autodesk.DesignScript.Geometry.Solid> iSS = new List <Autodesk.DesignScript.Geometry.Solid>(); foreach (Autodesk.Revit.DB.Element el in interElem) { GeometryElement intEl = el.get_Geometry(new Options()); foreach (GeometryObject intObj in intEl) { iS.Add(intObj as Autodesk.Revit.DB.Solid); } } foreach (Autodesk.Revit.DB.Solid s0 in elGeoms) { foreach (Autodesk.Revit.DB.Solid s1 in iS) { Autodesk.Revit.DB.Solid i = BooleanOperationsUtils.ExecuteBooleanOperation(s0, s1, BooleanOperationsType.Intersect); if (i != null) { Autodesk.Revit.DB.Solid bbox = f.CreateSolidFromBoundingBox(i); iSS.Add(Revit.GeometryConversion.RevitToProtoSolid.ToProtoType(i)); } } } interGeoms.Add(iSS); } } } return(interGeoms); }