diff --git a/art/gh-icons/comps/QueryVisibleElements.png b/art/gh-icons/comps/QueryVisibleElements.png new file mode 100644 index 000000000..3f0a0b4c7 Binary files /dev/null and b/art/gh-icons/comps/QueryVisibleElements.png differ diff --git a/art/gh-icons/comps/src/QueryVisibleElements.afdesign b/art/gh-icons/comps/src/QueryVisibleElements.afdesign new file mode 100644 index 000000000..7b606df52 Binary files /dev/null and b/art/gh-icons/comps/src/QueryVisibleElements.afdesign differ diff --git a/docs/pages/_en/1.0/reference/release-notes.md b/docs/pages/_en/1.0/reference/release-notes.md index f0a11871b..83c8702e3 100644 --- a/docs/pages/_en/1.0/reference/release-notes.md +++ b/docs/pages/_en/1.0/reference/release-notes.md @@ -18,8 +18,10 @@ group: Deployment & Configs - Added 'Component Reference Plane' component. - Added 'Reference Annotations' component. - Improved 'Host Shape' performance. -- Now 'Query View Elements' filters out hidden on UI categories. +- Now 'Query View Elements' filters out hidden UI categories. - Added 'Is Visible UI' to 'Query Categories' and 'Category Identity'. +- Added 'Query View Owned Elements' component. +- Renamed 'Query View Elements' to 'Query Visible Elements'. {% endcapture %} {% include ltr/release_header_next.html title="Upcoming Changes" note=rc_release_notes %} diff --git a/src/RhinoInside.Revit.External/DB/Extensions/Document.cs b/src/RhinoInside.Revit.External/DB/Extensions/Document.cs index be2bdbcc8..cb3a896de 100644 --- a/src/RhinoInside.Revit.External/DB/Extensions/Document.cs +++ b/src/RhinoInside.Revit.External/DB/Extensions/Document.cs @@ -709,12 +709,12 @@ public static Category GetCategory(this Document doc, BuiltInCategory categoryId if (Category.GetCategory(doc, categoryId) is Category category) return category; } - catch (Autodesk.Revit.Exceptions.InvalidOperationException) { } + catch { } // 2. Try looking for any GraphicsStyle that points to the Category we are looking for. using (var collector = new FilteredElementCollector(doc).OfClass(typeof(GraphicsStyle))) { - foreach (var style in collector.Cast()) + foreach (var style in collector.ToElements().Cast()) { var category = style.GraphicsStyleCategory; if (category.Id.ToBuiltInCategory() == categoryId) diff --git a/src/RhinoInside.Revit.GH/Components/Element/QueryElements.cs b/src/RhinoInside.Revit.GH/Components/Element/QueryElements.cs index 541513fae..80ea1e5de 100644 --- a/src/RhinoInside.Revit.GH/Components/Element/QueryElements.cs +++ b/src/RhinoInside.Revit.GH/Components/Element/QueryElements.cs @@ -144,16 +144,16 @@ protected override void TrySolveInstance(IGH_DataAccess DA) } } - public class QueryViewElements : ElementCollectorComponent + public class QueryVisibleElements : ElementCollectorComponent { public override Guid ComponentGuid => new Guid("79DAEA3A-13A3-49BF-8BEB-AA28E3BE4515"); public override GH_Exposure Exposure => GH_Exposure.secondary; protected override ARDB.ElementFilter ElementFilter => new ARDB.ElementIsElementTypeFilter(inverted: true); - public QueryViewElements() : base + public QueryVisibleElements() : base ( - name: "Query View Elements", - nickname: "ViewEles", + name: "Query Visible Elements", + nickname: "VisEles", description: "Get elements visible in a view", category: "Revit", subCategory: "Element" @@ -212,8 +212,8 @@ protected override void TrySolveInstance(IGH_DataAccess DA) ( "Elements", elementCollector. - Where(x => Types.GraphicalElement.IsValidElement(x)). Select(Types.GraphicalElement.FromElement). + OfType(). TakeWhileIsNotEscapeKeyDown(this) ); } diff --git a/src/RhinoInside.Revit.GH/Components/Views/QueryViewElements.cs b/src/RhinoInside.Revit.GH/Components/Views/QueryViewElements.cs new file mode 100644 index 000000000..5733c64c2 --- /dev/null +++ b/src/RhinoInside.Revit.GH/Components/Views/QueryViewElements.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Grasshopper.Kernel; +using ARDB = Autodesk.Revit.DB; +using ERDB = RhinoInside.Revit.External.DB; + +namespace RhinoInside.Revit.GH.Components.Views +{ + using External.DB.Extensions; + + [ComponentVersion(introduced: "1.16")] + public class QueryViewElements : ElementCollectorComponent + { + public override Guid ComponentGuid => new Guid("92B3F600-40FB-4DD3-992B-68B68D284167"); + public override GH_Exposure Exposure => GH_Exposure.quarternary; + protected override ARDB.ElementFilter ElementFilter => new ARDB.ElementIsElementTypeFilter(inverted: true); + + public QueryViewElements() : base + ( + name: "Query View Owned Elements", + nickname: "ViewEles", + description: "Get elements owned by a view", + category: "Revit", + subCategory: "View" + ) + { } + + protected override ParamDefinition[] Inputs => inputs; + static readonly ParamDefinition[] inputs = + { + ParamDefinition.Create("View", "V", "View", GH_ParamAccess.item), + ParamDefinition.Create("Categories", "C", "Category", GH_ParamAccess.list, optional: true), + ParamDefinition.Create("Filter", "F", "Filter", GH_ParamAccess.item, optional: true), + }; + + protected override ParamDefinition[] Outputs => outputs; + static readonly ParamDefinition[] outputs = + { + ParamDefinition.Create("Elements", "E", "Elements list", GH_ParamAccess.list) + }; + + protected override void TrySolveInstance(IGH_DataAccess DA) + { + if (!Params.GetData(DA, "View", out Types.View view, x => x.IsValid)) return; + if (!Params.TryGetDataList(DA, "Categories", out IList categories)) return; + if (!Params.TryGetData(DA, "Filter", out ARDB.ElementFilter filter, x => x.IsValidObject)) return; + + using (var collector = new ARDB.FilteredElementCollector(view.Document)) + { + var elementCollector = collector.WherePasses(ElementFilter); + + elementCollector = elementCollector.OwnedByView(view.Id); + + if (categories is object) + { + var ids = categories. + Where(x => x?.IsValid == true && (x.Document is null || x.Document.Equals(view.Document))). + Select(x => x.Id).ToArray(); + + elementCollector = elementCollector.WherePasses + ( + ERDB.CompoundElementFilter.ElementCategoryFilter(ids, inverted: false, view.Document.IsFamilyDocument) + ); + } + else + { + // Default category filtering + var hiddenCategories = BuiltInCategoryExtension.GetHiddenInUIBuiltInCategories(view.Document) as ICollection; + elementCollector = elementCollector.WherePasses + ( + new ARDB.ElementMulticategoryFilter(hiddenCategories, inverted: true) + ); + } + + if (filter is object) + elementCollector = elementCollector.WherePasses(filter); + + DA.SetDataList + ( + "Elements", + elementCollector. + Select(Types.GraphicalElement.FromElement). + OfType(). + TakeWhileIsNotEscapeKeyDown(this) + ); + } + } + } +} diff --git a/src/RhinoInside.Revit.GH/Properties/Resources.resx b/src/RhinoInside.Revit.GH/Properties/Resources.resx index 7d7e33196..3604fe178 100755 --- a/src/RhinoInside.Revit.GH/Properties/Resources.resx +++ b/src/RhinoInside.Revit.GH/Properties/Resources.resx @@ -823,6 +823,9 @@ ..\..\..\art\gh-icons\comps\QueryViewElements.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\..\..\art\gh-icons\comps\QueryVisibleElements.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\..\..\art\gh-icons\comps\RailingByCurve.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/src/RhinoInside.Revit.GH/RhinoInside.Revit.GH.csproj b/src/RhinoInside.Revit.GH/RhinoInside.Revit.GH.csproj index 82bcc8a88..bdabf4133 100644 --- a/src/RhinoInside.Revit.GH/RhinoInside.Revit.GH.csproj +++ b/src/RhinoInside.Revit.GH/RhinoInside.Revit.GH.csproj @@ -294,6 +294,7 @@ +