Ghost Elements When Undoing With 'DocumentChanged' Event Active

Hi! New here in pyRevit and hoping to learn more. :wave:

I’m currently using the telemetry feature in pyRevit to send data on changed elements using the DocumentChanged event. It works, but I’m facing a small issue that could become annoying if not resolved.
When I enable it—whether through Script Telemetry for doc-changed.py hooks or Application Telemetry for the DocumentChanged event—undoing a created element doesn’t remove it immediately. Instead, it remains as a ‘ghost’ until the view is zoomed or panned. Only then the element is removed.

I tried this on a new device with the latest pyRevit, and the issue still occurs. I’m worried that when people in my company face this problem, they’ll keep undoing multiple times, thinking their action wasn’t registered. But once it updates, they’ll realize it actually was, leading to multiple unintended undos.

Haven’t really seen any similar topic so if anyone can help out, that’ll be great. Thankyou!

1 Like

Hi, Welcome Alvin,

Haven’t used telemetry in years, not sure that many people are using it.
Would you have a minimal example to be able to reproduce quickly?

1 Like

Oh, that’s surprising. I guess that explains why there isn’t much discussion about telemetry. Now I’m starting to wonder if what I’m working on is worth doing haha

Anyway, you can reproduce this issue by enabling the telemetry feature in pyRevit and either:

  • Turning on the Application Telemetry then check the Document Changed events.

  • Or Turning on the Script Telemetry then check Hooks in ‘Send Telemetry For’. Then create a hook script named doc-changed.py. In my case I use the following code to send the information element :

Code

I know it’s not the most efficient script so bear with me—I’m still new to this. :wilted_flower:

from Autodesk.Revit.DB import ElementId
from pyrevit import script

# Variables
sender = __eventsender__
args = __eventargs__
result = script.get_results()

# Get the document
doc = args.GetDocument()

# Function to extract UniqueId from ElementId
def get_unique_ids(doc, element_ids):
    return [doc.GetElement(el_id).UniqueId for el_id in element_ids if doc.GetElement(el_id)]

# Convert .NET List[ElementId] to Python lists
modified_el_ids = list(args.GetModifiedElementIds())
deleted_el_ids = list(args.GetDeletedElementIds())
added_el_ids = list(args.GetAddedElementIds())

# Get UniqueIds corresponding to those ElementIds
modified_unique_ids = get_unique_ids(doc, modified_el_ids)
deleted_unique_ids = get_unique_ids(doc, deleted_el_ids)
added_unique_ids = get_unique_ids(doc, added_el_ids)

# Store results separately for ElementIds and UniqueIds
result.modified_element_ids = [el_id.IntegerValue for el_id in modified_el_ids]
result.deleted_element_ids = [el_id.IntegerValue for el_id in deleted_el_ids]
result.added_element_ids = [el_id.IntegerValue for el_id in added_el_ids]


result.modified_unique_ids = modified_unique_ids
result.deleted_unique_ids = deleted_unique_ids
result.added_unique_ids = added_unique_ids

# Count length of each list
result.modified_count = len(modified_el_ids)
result.deleted_count = len(deleted_el_ids)
result.added_count = len(added_el_ids)

# Send Document Name
result.doc_name = doc.Title 

Now, with telemetry active, when I create walls and then undo them, they remain as “ghosts” until I pan or zoom the view. This only happens with the DocumentChanged event—other events don’t seem to cause the issue.

I hope this explanation makes sense! Let me know if you need more details.

…all elements? That’s quite a bit of overhead.
Some events requite a doc.Regenerate() to refresh the database and display. Again, that can add a lot of overhead.
We would need more detail to see what is going on.