How to extract elements in a group?

Hi all, Is there a way to extract elements within a group without ungroup them within Revit?

You can use GetMemberids method from the Group Class and then use the Query Element Component to get the Elements

The following code is automatically generated by the Rhino.Inside.Revit GPT. Just copy and paste in the Python node and it will give you the ids of the members


import clr
clr.AddReference("RhinoCommon")
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
clr.AddReference("RhinoInside.Revit")

from Rhino.Geometry import *
from RhinoInside.Revit import Revit
from Autodesk.Revit import DB

doc = Revit.ActiveDBDocument

# ---- Inputs provided by Grasshopper ----
# Execute : bool
# Groups : Autodesk.Revit.DB.Group or list[Autodesk.Revit.DB.Group]

if not Execute:
    Result = None
else:
    try:
        Result = []

        group_items = Groups

        if group_items is None:
            raise Exception("Groups input is None.")

        if isinstance(group_items, DB.Group):
            group_items = [group_items]
        elif not isinstance(group_items, (list, tuple)):
            raise Exception("Groups must be an Autodesk.Revit.DB.Group or a list of Autodesk.Revit.DB.Group.")

        for group in group_items:
            if group is None or not isinstance(group, DB.Group):
                continue

            member_ids = group.GetMemberIds()

            for member_id in member_ids:
                member = doc.GetElement(member_id)
                if member is not None:
                    Result.append(member)

    except Exception as e:
        Result = str(e)

Cool, thanks Muhammad!

@Jack_Zeng there is a native component Group members you can use that one.

I just saw it :slight_smile: