Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved 'Query View Owned Elements' component. #990

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added art/gh-icons/comps/QueryViewOwnedElements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions docs/pages/_en/1.0/reference/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ group: Deployment & Configs
- Added 'Component Reference Plane' component.
- Added 'Reference Annotations' component.
- Improved 'Host Shape' performance.
- Now 'Query View Elements' filters out hidden UI _Categories_.
- Renamed 'Query View Elements' -> 'Query Graphical Elements'.
- Now 'Query Graphical Elements' filters out hidden UI _Categories_.
- Added 'Is Visible UI' to 'Query Categories' and 'Category Identity'.
- Added 'Query View Elements' component.
- Added 'Query View Owned Elements' component.
- Renamed 'Query View Elements' -> 'Query Visible Elements'.
- Added 'Query Title Blocks' component.
- Added 'Query Viewports' component.
- Fixed 'Element Name' when used to rename _Subcategories_ in multiple families at once.
[#898](https://github.com/mcneel/rhino.inside-revit/issues/898)
- Fix on 'Query Categories' it should output ordered by id.
- Fix on 'Query Visible Elements' when a `<None>` category is used.
- Fix on 'Query Graphical Elements' when a `<None>` category is used.
- 'Element Subcategory' compoennt now works on `GenericForm` elements.
- Added 'Add Schedule Graphics' component.
[#871](https://github.com/mcneel/rhino.inside-revit/issues/871)
Expand Down
5 changes: 5 additions & 0 deletions src/RhinoInside.Revit.External/DB/CompoundElementFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ internal static ElementFilter ElementIsNotInternalFilter(Document doc)
public static ElementFilter ElementHasCategoryFilter { get; } = new ElementCategoryFilter(BuiltInCategory.INVALID, inverted: true);
private static ElementFilter ElementIsElementTypeFilterInstance { get; } = new ElementIsElementTypeFilter(inverted: false);
private static ElementFilter ElementIsNotElementTypeFilterInstance { get; } = new ElementIsElementTypeFilter(inverted: true);
private static ElementFilter ElementIsViewSpecific { get; } = new ElementOwnerViewFilter(ElementIdExtension.Invalid, inverted: true);
private static ElementFilter ElementIsNotViewSpecific { get; } = new ElementOwnerViewFilter(ElementIdExtension.Invalid, inverted: false);
private static FilterNumericRuleEvaluator NumericEqualsEvaluator { get; } = new FilterNumericEquals();
private static ParameterValueProvider SubCategoryParamProvider { get; } = new ParameterValueProvider(new ElementId(BuiltInParameter.FAMILY_ELEM_SUBCATEGORY));
private static ParameterValueProvider FamilyNameParamProvider { get; } = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME));
Expand Down Expand Up @@ -205,6 +207,9 @@ public static ElementFilter ElementKindFilter(ElementKind kind, bool? elementTyp
public static ElementFilter ElementIsElementTypeFilter(bool inverted = false) => inverted ?
ElementIsNotElementTypeFilterInstance : ElementIsElementTypeFilterInstance;

public static ElementFilter ElementIsViewSpecificFilter(bool inverted = false) => inverted ?
ElementIsNotViewSpecific : ElementIsViewSpecific;

public static ElementFilter ElementCategoryFilter(ICollection<ElementId> categoryIds, bool inverted = false, bool includeSubCategories = false)
{
if (categoryIds.Count == 0) return inverted ? Universe : Empty;
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.GH/Components/Element/Geometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public ElementViewGeometry() : base
nickname: "ViewGeom",
description: "Get the geometry of the given Element on a view",
category: "Revit",
subCategory: "Element"
subCategory: "View"
)
{ }

Expand Down
17 changes: 8 additions & 9 deletions src/RhinoInside.Revit.GH/Components/Element/QueryElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
}
}

public class QueryVisibleElements : ElementCollectorComponent
public class QueryGraphicalElements : 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 QueryVisibleElements() : base
public QueryGraphicalElements() : base
(
name: "Query Visible Elements",
nickname: "VisEles",
description: "Get elements visible in a view",
name: "Query Graphical Elements",
nickname: "G-Elements",
description: "Get graphical elements visible in a view",
category: "Revit",
subCategory: "Element"
)
Expand Down Expand Up @@ -199,10 +199,9 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
else
{
// Default category filtering
var hiddenCategories = BuiltInCategoryExtension.GetHiddenInUIBuiltInCategories(view.Document).
Append(ARDB.BuiltInCategory.OST_SectionBox). // 'Section Boxes' has little sense here!?!?
Append(ARDB.BuiltInCategory.INVALID). // `ScheduleSheetInstance` Viewer has no Category, so we filter here
ToList();
var hiddenCategories = BuiltInCategoryExtension.GetHiddenInUIBuiltInCategories(view.Document).ToList();
hiddenCategories.Add(ARDB.BuiltInCategory.OST_SectionBox); // 'Section Boxes' has little sense here!?!?
hiddenCategories.Add(ARDB.BuiltInCategory.INVALID); // `ScheduleSheetInstance` Viewer has no Category, so we filter here

elementCollector = elementCollector.WherePasses
(
Expand Down
10 changes: 5 additions & 5 deletions src/RhinoInside.Revit.GH/Components/Element/Visibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace RhinoInside.Revit.GH.Components.Elements
{
[ComponentVersion(introduced: "1.13")]
[ComponentVersion(introduced: "1.13", updated: "1.16")]
public class ElementVisibility : ZuiComponent
{
public override Guid ComponentGuid => new Guid("8ED1490F-DA5D-40FA-8612-4F4B166ECE52");
Expand All @@ -23,7 +23,7 @@ public ElementVisibility() : base
nickname: "Visibility",
description: "Check element visibility on a given View",
category: "Revit",
subCategory: "Element"
subCategory: "View"
)
{ }

Expand All @@ -32,7 +32,7 @@ public ElementVisibility() : base
{
new ParamDefinition
(
new Parameters.GraphicalElement()
new Parameters.Element()
{
Name = "Element",
NickName = "E",
Expand All @@ -56,7 +56,7 @@ public ElementVisibility() : base
{
new ParamDefinition
(
new Parameters.GraphicalElement()
new Parameters.Element()
{
Name = "Element",
NickName = "E",
Expand Down Expand Up @@ -88,7 +88,7 @@ public ElementVisibility() : base

protected override void TrySolveInstance(IGH_DataAccess DA)
{
if (!Params.GetDataList(DA, "Element", out IList<Types.GraphicalElement> elements)) return;
if (!Params.GetDataList(DA, "Element", out IList<Types.Element> elements)) return;
else Params.TrySetDataList(DA, "Element", () => elements);

if (!Params.GetData(DA, "View", out Types.View view, x => x.IsValid)) return;
Expand Down
91 changes: 85 additions & 6 deletions src/RhinoInside.Revit.GH/Components/Views/QueryViewElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,99 @@
namespace RhinoInside.Revit.GH.Components.Views
{
using External.DB.Extensions;
using RhinoInside.Revit.External.DB;

[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;
public override Guid ComponentGuid => new Guid("ECC6FA17-ED92-4166-B47D-A32D50FA8475");
public override GH_Exposure Exposure => GH_Exposure.secondary;
protected override ARDB.ElementFilter ElementFilter => new ARDB.ElementIsElementTypeFilter(inverted: true);

public QueryViewElements() : base
(
name: "Query View Elements",
nickname: "V-Elements",
description: "Get elements visible in a view",
category: "Revit",
subCategory: "View"
)
{ }

protected override ParamDefinition[] Inputs => inputs;
static readonly ParamDefinition[] inputs =
{
ParamDefinition.Create<Parameters.View>("View", "V", "View", GH_ParamAccess.item),
ParamDefinition.Create<Parameters.Category>("Categories", "C", "Category", GH_ParamAccess.list, optional: true),
ParamDefinition.Create<Parameters.ElementFilter>("Filter", "F", "Filter", GH_ParamAccess.item, optional: true),
};

protected override ParamDefinition[] Outputs => outputs;
static readonly ParamDefinition[] outputs =
{
ParamDefinition.Create<Parameters.Element>("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<Types.Category> categories)) return;
if (!Params.TryGetData(DA, "Filter", out ARDB.ElementFilter filter, x => x.IsValidObject)) return;

using (var collector = new ARDB.FilteredElementCollector(view.Document, view.Id))
{
var elementCollector = collector.WherePasses(ElementFilter);

if (categories is object)
{
var ids = categories.
Where(x => x is object && (x.IsEmpty || x.IsValid) && (x.Document is null || x.Document.Equals(view.Document))).
Select(x => x.Id).
ToList();

elementCollector = elementCollector.WherePasses
(
ERDB.CompoundElementFilter.ElementCategoryFilter(ids, inverted: false, view.Document.IsFamilyDocument)
);
}
else
{
// Default category filtering
var hiddenCategories = BuiltInCategoryExtension.GetHiddenInUIBuiltInCategories(view.Document).ToList();
hiddenCategories.Add(ARDB.BuiltInCategory.OST_SectionBox); // 'Section Boxes' has little sense here!?!?
hiddenCategories.Add(ARDB.BuiltInCategory.INVALID); // `ScheduleSheetInstance` Viewer has no Category, so we filter here

elementCollector = elementCollector.WherePasses
(
new ARDB.ElementMulticategoryFilter(hiddenCategories, inverted: true)
);
}

if (filter is object)
elementCollector = elementCollector.WherePasses(filter);

DA.SetDataList
(
"Elements",
elementCollector.
Select(Types.Element.FromElement).
TakeWhileIsNotEscapeKeyDown(this)
);
}
}
}

[ComponentVersion(introduced: "1.16")]
public class QueryViewOwnedElements : 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 => CompoundElementFilter.ElementIsViewSpecificFilter();

public QueryViewOwnedElements() : base
(
name: "Query View Owned Elements",
nickname: "ViewEles",
nickname: "VO-Elements",
description: "Get elements owned by a view",
category: "Revit",
subCategory: "View"
Expand Down Expand Up @@ -48,9 +129,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA)

using (var collector = new ARDB.FilteredElementCollector(view.Document))
{
var elementCollector = collector.WherePasses(ElementFilter);

elementCollector = elementCollector.OwnedByView(view.Id);
var elementCollector = collector.OwnedByView(view.Id);

if (categories is object)
{
Expand Down
7 changes: 5 additions & 2 deletions src/RhinoInside.Revit.GH/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,11 @@
<data name="QueryViewElements" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\QueryViewElements.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="QueryVisibleElements" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\QueryVisibleElements.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="QueryViewOwnedElements" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\QueryViewOwnedElements.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="QueryGraphicalElements" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\QueryGraphicalElements.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="RailingByCurve" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\RailingByCurve.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
Expand Down
Loading