Hey, i am working on a dynamo code where it finds and deletes the duplicate instances from an error message.
This is the code, but here is the issue: If there are 4 same instances on the same place, it just deletes one of them and keeps the other 3. To reduce the number to 1 instance, i need to run it multiple times. Could someone help me to fix this issue, please?
I appreciate all feedbacks, thank you.
P.S: Revit version is 2026.
iirc Lists.DuplicateItemIndices gives you lists of index of duplicates, like[ [0,3,4], [5,9,12] ]. then you List.Map with List.RestOfItems to get [3, 4], [9, 12] excluding 0 and 5. And then List.GetItemAtIndex to obtain the elements and remove them.
and be careful with this kind of location comparison, floating point precision can lead to false positive.
Let try delete it by Python node :
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
warnings = doc.GetWarnings()
deletedIds = []
TransactionManager.Instance.EnsureInTransaction(doc)
try:
for warning in warnings:
failureId = warning.GetFailureDefinitionId()
if (failureId == BuiltInFailures.OverlapFailures.DuplicateInstances):
ids = list(warning.GetFailingElements())
if len(ids) >= 2:
try:
doc.Delete(ids[-1])
deletedIds.append(ids[-1])
except:
pass
finally:
TransactionManager.Instance.TransactionTaskDone()
OUT = deletedIds

