Skip to content

Commit

Permalink
First try to Query linked elements on a view.
Browse files Browse the repository at this point in the history
  • Loading branch information
kike-garbo committed Dec 18, 2023
1 parent 1871c51 commit 0f46e30
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/RhinoInside.Revit.External/DB/CompoundElementFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ public static ElementFilter ThatExcludes(this ElementFilter self, params Element
#endregion

#region Geometry
public static ElementFilter GraphicalElementFilter { get; } = Intersect
(
ElementIsNotElementTypeFilterInstance,
ElementHasCategoryFilter,
ElementHasBoundingBoxFilter.Union(ElementClassFilter(typeof(DatumPlane)))
);

public static ElementFilter BoundingBoxIntersectsFilter(Outline outline, double tolerance, bool inverted)
{
if (outline.IsEmpty)
Expand Down
41 changes: 29 additions & 12 deletions src/RhinoInside.Revit.GH/Components/Element/QueryElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace RhinoInside.Revit.GH.Components.Elements
{
using External.DB;
using External.DB.Extensions;

public class QueryElement : ZuiComponent
Expand Down Expand Up @@ -149,7 +150,7 @@ 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);
protected override ARDB.ElementFilter ElementFilter => CompoundElementFilter.GraphicalElementFilter;

public QueryGraphicalElements() : base
(
Expand All @@ -165,6 +166,7 @@ public QueryGraphicalElements() : base
static readonly ParamDefinition[] inputs =
{
ParamDefinition.Create<Parameters.View>("View", "V", "View", GH_ParamAccess.item),
//ParamDefinition.Create<Parameters.GraphicalElement>("Link", "L", "Linked Model", GH_ParamAccess.item, optional: true, relevance: ParamRelevance.Secondary),
ParamDefinition.Create<Parameters.Category>("Categories", "C", "Category", GH_ParamAccess.list, optional: true),
ParamDefinition.Create<Parameters.ElementFilter>("Filter", "F", "Filter", GH_ParamAccess.item, optional: true),
};
Expand All @@ -178,12 +180,13 @@ public QueryGraphicalElements() : base
protected override void TrySolveInstance(IGH_DataAccess DA)
{
if (!Params.GetData(DA, "View", out Types.View view, x => x.IsValid)) return;
if (!Params.TryGetData(DA, "Link", out Types.RevitLinkInstance link, 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))
using (var collector = view.Value.GetVisibleElementsCollector(link?.Id))
{
var elementCollector = collector.WherePasses(ElementFilter);
var elementCollector = collector;

if (categories is object)
{
Expand All @@ -194,7 +197,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA)

elementCollector = elementCollector.WherePasses
(
ERDB.CompoundElementFilter.ElementCategoryFilter(ids, inverted: false, view.Document.IsFamilyDocument)
CompoundElementFilter.ElementCategoryFilter(ids, inverted: false, view.Document.IsFamilyDocument)
);
}
else
Expand All @@ -213,14 +216,28 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
if (filter is object)
elementCollector = elementCollector.WherePasses(filter);

DA.SetDataList
(
"Elements",
elementCollector.
Select(Types.GraphicalElement.FromElement).
OfType<Types.GraphicalElement>().
TakeWhileIsNotEscapeKeyDown(this)
);
if (link is object)
{
DA.SetDataList
(
"Elements",
elementCollector.
Select(x => Types.GraphicalElement.FromLinkElement(link, Types.GraphicalElement.FromElement(x))).
OfType<Types.GraphicalElement>().
TakeWhileIsNotEscapeKeyDown(this)
);
}
else
{
DA.SetDataList
(
"Elements",
elementCollector.
Select(Types.GraphicalElement.FromElement).
OfType<Types.GraphicalElement>().
TakeWhileIsNotEscapeKeyDown(this)
);
}
}
}
}
Expand Down

0 comments on commit 0f46e30

Please sign in to comment.