Count Group (Model and Details), Instances and Types Without Arrays Counted as Groups

Double post here
I hate when people do this, but for this one time…

I have 4 different functions that fetch:

  • model group instances count

  • model group types count

  • detail groups instances count

and you guessed it…

  • detail groups types count

for model group instances, I go with:

model_groups_instances_ids = (
        DB.FilteredElementCollector(doc)
        .OfCategory(DB.BuiltInCategory.OST_IOSModelGroups)
        .WhereElementIsNotElementType()
        .ToElementIds()
    )
arrays_groups_ids = [array.IntegerValue for array in q.get_array_group_ids(doc)]
return len([model_group_id for model_group_id in model_groups_instances_ids if model_group_id.IntegerValue not in arrays_groups_ids])

where get_array_group_ids is:

def get_array_group_ids(doc=None):
    """
    Collects and returns the IDs of all array groups in the given document.

    Args:
        document (DB.Document): The Revit document to search for array groups.

    Returns:
        list: A list of element IDs representing the array groups.
    """
    array_list = DB.FilteredElementCollector(doc or DOCS.doc).OfCategory(
        DB.BuiltInCategory.OST_IOSArrays
    )
    arrays_groups = []
    for ar in array_list:
        arrays_groups.extend(ar.GetOriginalMemberIds())
        arrays_groups.extend(ar.GetCopiedMemberIds())
    return set(arrays_groups)

The count is right in a very simple example file containing arrays I made and groups I made.

In the latest Revit arch sample (2024), for example, the count if off… and I don’t get why…

Any pointer appreciated; I spent way too much time on this already.

I ran this in Revit Python Shell on the Revit 2024 sample and got the same for each. A count total of 80.

array_list = FilteredElementCollector(doc or DOCS.doc).OfCategory(BuiltInCategory.OST_IOSArrays)
numberof = 0
for ar in array_list:
	copied = ar.GetCopiedMemberIds()
	original = ar.GetOriginalMemberIds()
	numberof = numberof + copied.Count + original.Count
print(numberof)

array_list = FilteredElementCollector(doc or DOCS.doc).OfCategory(BuiltInCategory.OST_IOSArrays)
arrays_groups = []
for ar in array_list:
    arrays_groups.extend(ar.GetOriginalMemberIds())
    arrays_groups.extend(ar.GetCopiedMemberIds())
print(len(arrays_groups))

Ah arrays.
As I always shout out loud when someone at the office says the word array: “hip hip array” (pronouncing it as “hip hip hoorray!”)

not tested it, but throwing it at you anyways:

  1. is it always an IntergerValue?
  2. you “set” in set(arrays_groups) while you don’t that in model_groups_instances_ids.
  3. are you sure getcopied and getoriginal return the same value everytime? I’ve have mixed feelings about arrays.