Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to filter for element IDs of groups matching groupname. Can anybody help me with this?
James LeVieux
Solved! Go to Solution.
I want to filter for element IDs of groups matching groupname. Can anybody help me with this?
James LeVieux
Solved! Go to Solution.
VB
Public Function Execute_GroupNameFilter(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData, _ ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) _ As Autodesk.Revit.UI.Result Dim UIDoc As Autodesk.Revit.UI.UIDocument = commandData.Application.ActiveUIDocument If UIDoc Is Nothing Then Return Result.Cancelled Else Dim Doc As Document = UIDoc.Document Dim FEC As New FilteredElementCollector(Doc) Dim ECF1 As New ElementCategoryFilter(BuiltInCategory.OST_IOSDetailGroups) Dim ECF2 As New ElementCategoryFilter(BuiltInCategory.OST_IOSModelGroups) Dim LorF As New LogicalOrFilter(ECF1, ECF2) Dim Els As List(Of ElementId) = FEC.WherePasses(LorF).WhereElementIsNotElementType.ToList. _ FindAll(Function(X) X.Name = "TheGroupIWant").Select(Function(v) v.Id).ToList UIDoc.Selection.SetElementIds(Els) Return Result.Succeeded End Function
C#
public Autodesk.Revit.UI.Result Execute_GroupNameFilter(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Autodesk.Revit.UI.UIDocument UIDoc = commandData.Application.ActiveUIDocument; if (UIDoc == null) return Result.Cancelled; Document Doc = UIDoc.Document; FilteredElementCollector FEC = new FilteredElementCollector(Doc); ElementCategoryFilter ECF1 = new ElementCategoryFilter(BuiltInCategory.OST_IOSDetailGroups); ElementCategoryFilter ECF2 = new ElementCategoryFilter(BuiltInCategory.OST_IOSModelGroups); LogicalOrFilter LorF = new LogicalOrFilter(ECF1, ECF2); List<ElementId> Els = FEC.WherePasses(LorF).WhereElementIsNotElementType().ToList().FindAll(X => X.Name == "TheGroupIWant").Select(v => v.Id).ToList(); UIDoc.Selection.SetElementIds(Els); return Result.Succeeded; }
Thanks for RPTHOMAS108‘s replay, this should works!
Yet another approach is to use shortcut OfClass API of FilteredElementCollector:
FilteredElementCollector coll = new FilteredElementCollector(this.Document); List<ElementId> groupIds = coll.OfClass(typeof(Group)) .ToList().FindAll(X => X.Name == "<Your group name>").Select(v => v.Id).ToList();
Hi, I'm trying to do something similar, but I want to create groups of filtered structural connections, however I don't know apriori how many groups will be and their names. any suggestions?
here i collected all structural connections in the view: