Skip to content

Commit

Permalink
Merge pull request #972 from mcneel/1.16
Browse files Browse the repository at this point in the history
1.16
  • Loading branch information
kike-garbo authored Jul 28, 2023
2 parents 7edacf2 + a2f501b commit 2e91992
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 8 deletions.
Binary file added art/gh-icons/comps/QueryVisibleElements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 3 additions & 1 deletion docs/pages/_en/1.0/reference/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
4 changes: 2 additions & 2 deletions src/RhinoInside.Revit.External/DB/Extensions/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GraphicsStyle>())
foreach (var style in collector.ToElements().Cast<GraphicsStyle>())
{
var category = style.GraphicsStyleCategory;
if (category.Id.ToBuiltInCategory() == categoryId)
Expand Down
10 changes: 5 additions & 5 deletions src/RhinoInside.Revit.GH/Components/Element/QueryElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -212,8 +212,8 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
(
"Elements",
elementCollector.
Where(x => Types.GraphicalElement.IsValidElement(x)).
Select(Types.GraphicalElement.FromElement).
OfType<Types.GraphicalElement>().
TakeWhileIsNotEscapeKeyDown(this)
);
}
Expand Down
90 changes: 90 additions & 0 deletions src/RhinoInside.Revit.GH/Components/Views/QueryViewElements.cs
Original file line number Diff line number Diff line change
@@ -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<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.GraphicalElement>("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))
{
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<ARDB.BuiltInCategory>;
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<Types.GraphicalElement>().
TakeWhileIsNotEscapeKeyDown(this)
);
}
}
}
}
3 changes: 3 additions & 0 deletions src/RhinoInside.Revit.GH/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@
<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>
<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>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/RhinoInside.Revit.GH/RhinoInside.Revit.GH.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
<Compile Include="Components\Views\Graphics\GraphicOverrides.cs" />
<Compile Include="Components\Views\Graphics\WorksetVisibilityOverrides.cs" />
<Compile Include="Components\Views\Identity.cs" />
<Compile Include="Components\Views\QueryViewElements.cs" />
<Compile Include="Components\Views\QueryViews.cs" />
<Compile Include="Components\Views\SectionBox.cs" />
<Compile Include="Components\Views\ViewRangeElevations.cs" />
Expand Down

0 comments on commit 2e91992

Please sign in to comment.