Filtering by "In Group" and 'Not in Group"

I have instances of the same family and some of them are grouped and some are not grouped. I would like to select all the items that are not in a group, but if I use the select all in view it selects the items in the groups as well.

Is there a way to select all the items in the view and then filter out all items that are part of a group?

I’m assuming there is a way even though it might be via API since I know by using the Revit Snoop button that there is a property associated with items in a group.

Thanks

You use Element Types and All Elements of Type (Element Classes and All Elements of Class in 2023) to get all the groups in your project. From there you can filter however you like and get their group members. Compare that to a list of all instances to get those not in groups.

The property you can access using the API is GroupId:

I’ve got a node in Crumple under Revit > Elements in Python for this:

image

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 

clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

# Define list/unwrap list functions
def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)

# Preparing input from dynamo to revit
items  = uwlist(IN[0])

itemgroup, hasgroup = [], []
	
# Get group and check if has group	
for i in items:
	if hasattr(i, "GroupId"):
		grp = i.Document.GetElement(i.GroupId)
		itemgroup.append(grp)
		if grp:
			hasgroup.append(True)
		else:
			hasgroup.append(False)
	else:
		itemgroup.append(None)

# Preparing output to Dynamo
OUT = [itemgroup, hasgroup]
4 Likes

Look into Get the Parent Group - #8 by awilliams

That worked perfectly.

I expanded on it adding UI so I could use it in my Pyrevit Toolbar

2 Likes