Query if Element is in a Revit Group?

Is it possible, given a list of elements, to query if they are in a group, by nodes or python? Or is the only way to do this is by getting all the groups, getting their members, and then comparing the lists?
I think the answer is that there isn’t a way to get the group an element belongs to directly, but haven’t worked with the API enough to be sure.

Use case: I’m trying to determine if collected doors are in a group, and if they are get the type mark of the group

Elements.Group in the Crumple package. I haven’t ever used it, but it’s supposed to do what you are wanting.

image

2 Likes

If you want to give python and the Revit API a shot, this would be a very good introduction. You can use element.GroupId to get the Id of the group that contains the given element.

4 Likes

Thanks! While I hate adding more packages to make sure the office has access to, this is the faster option to get the script working

Thank you! I’d like to start working more with Python/API, and prefer to minimize the additional packages used. I had tried to look through the api docs but hadn’t found the method you’d referenced, which is why I wasn’t sure it was possible. I’ll probably use Crumple temporarily to push the script to production, but will try to swap it out to Python as a good practice since it seems straightforward to learn on.

If you don’t use Revit Lookup yet you should look into it. I cannot recommend it enough.
GitHub - jeremytammik/RevitLookup

2 Likes

Quick fling to point out here… any time you decide to adopt an automation technology you are taking on a load of technical debt.

  • If you buy an add-in, you rely on it being updated year to year. Similarly, if you utilize a package, you rely on it being updated year to year.

  • If you write your own add-in, you rely on having the time to test and update it year to year. Similarly if you write your own code, you rely on having the time to test and update it year to year.

Due to the dynamic nature of Dynamo, Revit, Python, .NET and even Windows there is no such thing as ‘automation I can implement today and never have to update’. Further, you can’t rely on one automation across all Revit builds. As a result, what you push to users will have to be both maintained and deployed carefully. Don’t feel that ‘by writing Python I am saving myself all this time,’ as with the well managed and maintained packages that usually isn’t the case.

Don’t let that dissuade you from building something in Python as it is a great tool in your arsenal. But do go in with open eyes in that when you try the next Revit build you will need to test and as needed update all your automations.

3 Likes

Thanks, I don’t but will look into it.

I know, and this is is part of a rewrite of an existing script to address changes made and squash bugs. I do use, and will continue to use packages, but want to start using Python to a point where I understand what it is doing, and use it to access/test api calls that my standard packages don’t, or resolve errors created standard nodes. While I may end up continuing to use Crumple, finding the group an element is in is a more straightforwrd task for me to practice python on than some of my other ideas.

2 Likes