Skip to content

Commit

Permalink
add parameter element node
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Oct 8, 2024
1 parent 377ac52 commit edd99e9
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
78 changes: 78 additions & 0 deletions OpenMEPRevit/Element/ParameterFilterElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Autodesk.DesignScript.Runtime;
using Autodesk.Revit.DB;
using Dynamo.Graph.Nodes;
using Revit.Elements;
using Category = Revit.Elements.Category;

namespace OpenMEPRevit.Element;

[IsVisibleInDynamoLibrary(true)]
public class ParameterFilterElement
{
private ParameterFilterElement()
{
}

public List<Category>? Categories(Revit.Elements.Element parameterElement)
{
List<Category> categories = new List<Category>();
Autodesk.Revit.DB.ParameterFilterElement? parameterFilterElement = parameterElement.InternalElement as Autodesk.Revit.DB.ParameterFilterElement;
ICollection<ElementId>? elementIds = parameterFilterElement?.GetCategories();
if (elementIds == null)
{
return categories;
}
#if R20 || R21 || R22 || R23
foreach (ElementId elementId in elementIds)
{
categories.Add(Category.ById(elementId.IntegerValue));
}
#else
foreach (ElementId elementId in elementIds)
{
categories.Add(Category.ById(elementId.Value));
}
#endif
return categories;
}
/// <summary>
/// Return All Element Inside View Filter
/// </summary>
/// <param name="viewFilter"></param>
/// <returns name="elements">elements get from view filter</returns>
/// <example>
/// ![](../OpenMEPPage/element/dyn/pic/View.GetAllElementByViewFilter.png)
/// [View.GetAllElementByViewFilter.dyn](../OpenMEPPage/element/dyn/View.GetAllElementByViewFilter.dyn)
/// </example>
[NodeCategory("Action")]
[NodeSearchTags("get element")]
public static List<Revit.Elements.Element> GetAllElementByViewFilter(Revit.Elements.Element viewFilter)
{
Autodesk.Revit.DB.Document doc = viewFilter.InternalElement.Document;
Autodesk.Revit.DB.ParameterFilterElement? parameterFilterElement = viewFilter.InternalElement as Autodesk.Revit.DB.ParameterFilterElement;
if (parameterFilterElement == null)
return new List<Revit.Elements.Element>();
ElementFilter elementFilter = parameterFilterElement.GetElementFilter();
ICollection<ElementId> cates = parameterFilterElement.GetCategories();
IList<ElementFilter> eleFilters = new List<ElementFilter>();
foreach (var cat in cates)
{
eleFilters.Add(new ElementCategoryFilter(cat));
}
var cateFilter = new LogicalOrFilter(eleFilters);
if (elementFilter != null)
{
return new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.WherePasses(cateFilter)
.WherePasses(elementFilter)
.ToElements().Select(x => x.ToDSType(true)).ToList();
}
return new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.WherePasses(cateFilter)
.ToElements().Select(x => x.ToDSType(true)).ToList();
}
}
9 changes: 5 additions & 4 deletions OpenMEPRevit/Element/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ private View()
public static List<Revit.Elements.Element> GetAllViewFilters(bool flag)
{
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
List<ParameterFilterElement> parameterFilterElements = new FilteredElementCollector(doc)
.OfClass(typeof(ParameterFilterElement))
.OfType<ParameterFilterElement>()
List<Autodesk.Revit.DB.ParameterFilterElement> parameterFilterElements = new FilteredElementCollector(doc)
.OfClass(typeof(Autodesk.Revit.DB.ParameterFilterElement))
.OfType<Autodesk.Revit.DB.ParameterFilterElement>()
.OrderBy(x => x.Name)
.ToList();
if (parameterFilterElements.Count == 0)
Expand All @@ -43,12 +43,13 @@ private View()
/// ![](../OpenMEPPage/element/dyn/pic/View.GetAllElementByViewFilter.png)
/// [View.GetAllElementByViewFilter.dyn](../OpenMEPPage/element/dyn/View.GetAllElementByViewFilter.dyn)
/// </example>
[Obsolete("This method is obsolete, please use OpenMEPRevit.Element.ParameterFilterElement.GetAllElementByViewFilter instead.")]
[NodeCategory("Action")]
[NodeSearchTags("get element")]
public static List<Revit.Elements.Element> GetAllElementByViewFilter(Revit.Elements.Element viewFilter)
{
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
ParameterFilterElement? parameterFilterElement = viewFilter.InternalElement as ParameterFilterElement;
Autodesk.Revit.DB.ParameterFilterElement? parameterFilterElement = viewFilter.InternalElement as Autodesk.Revit.DB.ParameterFilterElement;
if (parameterFilterElement == null)
return new List<Revit.Elements.Element>();
ElementFilter elementFilter = parameterFilterElement.GetElementFilter();
Expand Down

0 comments on commit edd99e9

Please sign in to comment.