Deleting Identical instances?

Hey guys,
another question: Is there a node that I can use to delete identical instances in a model? I have 6819 instances of duplicate items.

1 Like

This returns all warnings with associated elements. You may have to filter through the “identical instances” warnings but this should get you started.

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

doc = DocumentManager.Instance.CurrentDBDocument

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
desc = []
out = []
#TransactionManager.Instance.EnsureInTransaction(doc)
warnings = doc.GetWarnings()
for w in warnings:
	desc.append(w.GetDescriptionText())
	ids = w.GetFailingElements()
	elements = []
	for i in ids:
		elements.append(doc.GetElement(i))
	out.append(elements)
#TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = desc,out
3 Likes

It’s on my BILT class material :slight_smile:

Nick, much Mahalo! I am getting errors when running this.What am I missing?

Python Script:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 13, in
AttributeError: ‘Document’ object has no attribute ‘GetWarnings’

Code Block
Warning: No item exists at specified index address

Daniel, What is your “BILT class material”?

I will say I am 100% new to Python.

A reference post on this topic to be found here:

Thanks Ill check it out!

Oh I forgot to mention… this will only work in 2018. :confused:
It’s not available in the API in previous versions. Check out @Yna_Db’s post about reading the error report. It’s not as quick and easy but it works for all versions.

ok shoot! were not authorized to upgrade the building yet. Thanks!

OK all, I followed what @Yna_Db posted and it lists the warnings. From here what would be the best method for deleting Just the duplicate items? I have 6819 identical instances.

You can try Element.Delete from Archi-Lab Grimshaw (use with caution)

Thanks, this model is in bad shape so let’s see if I can make it worse. :wink:
Can I filter just the duplicate items first? could I export to excel, delete what I want and import back and like magic the duplicates are gone?

The warnings should have the element IDs for each set of identical instances. You can use a node or some code to get the element by its ID. Then you just take all but one element from each group and delete them.

ok, looks like I’ll be doing some work this weekend. lol

I sorted out the duplicate items can I sort out by a “sub-category”? For instance: “#6800 List” has “0” and “1”. Can I sort out the “0” from the “1” and just see the “0”?
image

You can do that with Springs.List.GetEvenOdd but you will probably need to play with the level (try @L2)

If I haven’t said it yet, You ALL are awesome and I appreciate you guys!

Just learned what tha levels are for! thanks again Yha_Db!

List.Drop might be a better option here for future proofing reasons. Now you only have 2 instances of these items (pasted twice), but in the future you could have 3 (pasted, didn’t see it, and pasted again and again), 4 (two people pasting twice because the same red mark was on multiple drawings) or 45 (didn’t bother to ask due to the hilarity) identical instances in the future.

List.Drop with an input of 1 will quickly remove the first item (0 index) of every sub-list if you use the levels feature or set lacing to longest so you can delete all items at index 1 and beyond.