Delete Duplicate Families from Revit Model
16 May 2014
Here’s a quick definition that will delete all duplicate families from a Revit Model based on a Family Type. I considered families to be “duplicate” when I had the exact same Family Type in the exact same Location (you can achieve that by copying a family and then pasting it using command Paste>Aligned to same place). That will usually throw up an error saying that there are multiple instances in the same location and potentially they will get double counted in the schedule. Here’s the process:
Collect Families
First you need to collect all families that you are checking for duplicates. I used a Family Type selection node to get all of my chairs in the project:Gather Unique Data
Next, you need to gather some sort of unique data about that family to compare and determine if they are indeed duplicates. I used family location XYZ coordinates for that purpose:Get Element Location
Get Element Location is a custom node that can be downloaded from Package Manager. Once you collect the location of each element, it comes out as a “Revit point” and even though it looks like a string, it is not, thus you cannot compare them in Python. I used a “To String” node to convert the XYZ Point to a string and then search the list for duplicate “strings”.Custom Python Node
The next node is a custom Python node that looks at the whole list of coordinates and lists indices of those that are duplicate. Here’s a code that it uses:mylist = IN i, seen, result = mylist, set(), [] for _index, item in enumerate(i): if item not in seen: # First time seeing the element seen.add(item) else: # Already seen, add the index to the result result.append(_index) #Assign your output to the OUT variable OUT = resultOutput Duplicate Indices
The output of that operation is a list of Index numbers from the input list for all duplicate elements. You can then combine that with a “Get From List” node to extract all of the duplicate families from the original list:Delete Elements
The next node is a custom node that simply deletes any element that you feed into it. It will then display a list of elements and their IDs when it’s done deleting them. Here’s the code for it:#The input to this node will be stored in the IN variable. dataEnteringNode = IN doc = __doc__ result = [] result.append("Family ID " + IN.Id.ToString() + " was deleted.") doc.Delete(IN.Id) #Assign your output to the OUT variable OUT = reduce(lambda x,y: x.extend(y), result)
Good luck!
Note: The delete operation can be backed out of by going to the active Revit window and simply hitting “Undo” button. However, there is a finite number of undos, so be careful when running this script. I would recommend testing it on a detached model first.