如何在Autodesk Forge中获取隔离或剖面剖切对象的element ids?
Absolutely! You can definitely retrieve the Element IDs of isolated elements or those visible after a section cut using the Revit API—here's a breakdown of how to handle both scenarios:
获取隔离状态元素的Element IDs
Revit stores isolated elements in a dedicated filter tied to the active view. You can access this filter to extract the IDs directly:
using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System.Collections.Generic; using System.Linq; public List<ElementId> GetIsolatedElementIds(UIApplication uiapp) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; View activeView = uidoc.ActiveView; // Check if the view has an isolation filter applied if (activeView.IsolationFilterId != ElementId.InvalidElementId) { if (doc.GetElement(activeView.IsolationFilterId) is FilterElement isolationFilter) { // Extract the collection of isolated element IDs ElementIdCollection isolatedIds = isolationFilter.GetElementIds(); return isolatedIds.Cast<ElementId>().ToList(); } } // Return empty list if no elements are isolated return new List<ElementId>(); }
Notes:
- This works for both temporary and saved isolation states—Revit treats both the same under the hood via the
IsolationFilterIdproperty. - No transaction is needed here since we're only reading data from the model.
获取剖面剖切后可见元素的Element IDs
For section views, you'll need to check which elements are actually visible within the section's bounds. The View.DoesElementAppearInView() method handles the heavy lifting of checking against the section's crop and visibility settings:
using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System.Collections.Generic; public List<ElementId> GetSectionVisibleElementIds(UIApplication uiapp) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; View activeView = uidoc.ActiveView; // Verify we're working with a section view first if (!(activeView is ViewSection)) { throw new System.ArgumentException("The active view is not a section view."); } List<ElementId> visibleElementIds = new List<ElementId>(); // Collect elements in the section view (exclude element types if desired) FilteredElementCollector collector = new FilteredElementCollector(doc, activeView.Id) .WhereElementIsNotElementType(); foreach (Element elem in collector) { // Check if the element is visible in the section if (activeView.DoesElementAppearInView(elem.Id)) { visibleElementIds.Add(elem.Id); } } return visibleElementIds; }
Notes:
- For large models, narrow down your collector with category filters (e.g.,
OfCategory(BuiltInCategory.OST_Walls)) to improve performance. - This method accounts for both the section's crop region and any element-specific visibility overrides in the view.
内容的提问来源于stack exchange,提问作者Bi SAl MhRzn
相关产品推荐
相关产品推荐

