Get members of group

Get members of group

denisyukJ
Advocate Advocate
242 Views
1 Reply
Message 1 of 2

Get members of group

denisyukJ
Advocate
Advocate

 

Hi,

 

I woud like to get all elements included in a group. I found getmemberids method but can not apply it.

Could you please observe my code and say what am I doing wrong ot maybe give me hint how to proceed.

 

 

 

            // Retrieve elements from database

            IList<Element> col
              = new FilteredElementCollector(doc).
              OfCategory(BuiltInCategory.OST_IOSModelGroups).
              WhereElementIsNotElementType().
              ToElements();


            // Filtered element collector is iterable

            foreach (Element e in col)
            {
                ICollection<ElementId> ids = e.GetMemberIds();
                Debug.WriteLine(e);
            }

            return Result.Succeeded;

 

 

0 Likes
Accepted solutions (1)
243 Views
1 Reply
Reply (1)
Message 2 of 2

nice3point
Advocate
Advocate
Accepted solution

Missing cast to Group type:

 

var groups = new FilteredElementCollector(document)
        .OfCategory(BuiltInCategory.OST_IOSModelGroups)
        .WhereElementIsNotElementType()
        .ToElements();

foreach (var element in groups)
{
    var group = (Group)element;
    var memberIds = group.GetMemberIds();
    
    foreach (var memberId in memberIds)
    {
        var member = document.GetElement(memberId);
        Debug.WriteLine(member.Name);
    }
}

 

 

For better experience, use the RevitLookup analysis tool https://github.com/jeremytammik/RevitLookup