GetMemberIds() returning lots of elements from a linked document

GetMemberIds() returning lots of elements from a linked document

Anonymous
Not applicable
1,225 Views
6 Replies
Message 1 of 7

GetMemberIds() returning lots of elements from a linked document

Anonymous
Not applicable

Hi everyone,

 

I'm trying to get members of a group of a linked document. The group only has 4 elements which are walls or ceilings etc. However, the elements returned by GetMemberIds() are too many... It returns around 150 elements for one group... Elements are mostly Sketch, ModelLine, DatumPlane, or AnalyticalModelSurface. I only want to get real elements from the group to avoid over looping through the elements.

 

What am I missing? Why GetMemberIds() method returns that many elements?

 

 

filter = new ElementCategoryFilter(BuiltInCategory.OST_IOSModelGroups);
DocumentSet linkedDocs = commandData.Application.Application.Documents;
foreach (Document linkedDoc in linkedDocs)
{
collector = new FilteredElementCollector(linkedDoc);
groups = collector.WherePasses(filter).WhereElementIsNotElementType();
List<ElementId> memberIds = group.GetMemberIds().ToList();
...
....
.....
}

 

 

0 Likes
Accepted solutions (1)
1,226 Views
6 Replies
Replies (6)
Message 2 of 7

RPTHOMAS108
Mentor
Mentor

commandData.Application.Application.Documents

 

This contains all main documents you have open in Revit and all links open in those main documents. It is not the way to find elements in links. You can distinguish the link items in this set via Document.IsLink, however that doesn't indicate what main document it is linked into.

 

Most will instead filter for items of RvtLinkInstance in the main document and from there get the link document via RvtLinkInstance.GetLinkDocument.

 

It is unclear where 'group' comes from in your code example.

 

You can use a FilteredElementCollector on a set of ElementIds to further filter for categories of element etc. in your group.

 

 

0 Likes
Message 3 of 7

Anonymous
Not applicable

Hello RPTHOMAS, thanks for your answer,

 

Sorry, I forgot to mention where the "group" comes from. So just modified the code sample. And OK, I will change the way I get the linked document. Now I have only one open Model in Revit and other documents are linked to this Model. So I know with which model's linked Document I'm dealing with while debugging.

 

But do you think those elements from GetMemberIds() are coming from other Documents? Or why one group has this many members?   

 

 

filter = new ElementCategoryFilter(BuiltInCategory.OST_IOSModelGroups);
DocumentSet linkedDocs = commandData.Application.Application.Documents;
foreach (Document linkedDoc in linkedDocs)
{
collector = new FilteredElementCollector(linkedDoc);
groups = collector.WherePasses(filter).WhereElementIsNotElementType().ToList();
for(int i=0;i<groups.count;i++)
{
group = linkedDoc.GetElement(groups [i].Id) as Group;
List<ElementId> memberIds = group.GetMemberIds().ToList();
...
....
.....
}
}

 

 

0 Likes
Message 4 of 7

RPTHOMAS108
Mentor
Mentor

You would still be getting Groups from your main document as well as your links.

 

For the FilteredElementCollector you should yield results using .ToElements or .ToElementIds, as these are methods specific to the RevitAPI. .ToList is an extension method associated with IEnumerable<T>, which the collector class  implements.

 

In your case you can use .ToElementIds since you have the term:

 

group = linkedDoc.GetElement(groups [i].Id) as Group;

 

 

Which could then be simplified to:

 

group = linkedDoc.GetElement(groups[i]) as Group;

 

I've never had an issue getting too much of something, the elements are coming from somewhere.

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

I think groups are coming from the linked documents, not from the main document. Because of the collector.

collector = new FilteredElementCollector(linkedDoc);

 

After you get the group then I use GetMemberIds() to get the group members.

List<ElementId> memberIds = group.GetMemberIds().ToList();

 Here I get more elements than expected. The group only has 4 elements. memberIds List is being overpopulated somehow. With the elements that I mentioned before. Sketch, ModelLine, DatumPlane, or AnalyticalModelSurface

0 Likes
Message 6 of 7

Anonymous
Not applicable

Also tried the following line, but the same result 😞

 

List<Element> elementsInTheGroup = group.GetMemberIds().Select(q => doc.GetElement(q)).ToList();
0 Likes
Message 7 of 7

RPTHOMAS108
Mentor
Mentor
Accepted solution

Those elements are part of the wall, ceiling or wall.

 

Sketches and models lines are used in the creation of ceilings/floors/roofs etc.

Analytical surface will be included with structural elements such as walls and floors where 'Enable analytical model' is checked in the properties for such an element.

 

You can filter them out with a further FilteredElementCollector that passes the ElementIDs to the filter but they are in the group and that will not change.

0 Likes