How to use Revit api "Documentedchange Event" in Python?

I use Revit api “PostableCommand.DetailLine” to draw detailine,I want to retrieve the newly created element, it described here:

I try to convert it to python, but it doesn’t work,I got empty list, I think that I’m doing it wrong here
Any help would be much appreciated

from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Events import * 
import Autodesk
from Autodesk.Revit.DB.Events import *
from Autodesk.Revit.DB import * 
import Revit
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import List
import System
from System.Windows.Forms import *
from System.Drawing import *

def OnDocumentChanged (sender, e): 
	collection = e.GetAddedElementIds()

uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application       
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
listId = List[ElementId]()


uiapp.Application.DocumentChanged += OnDocumentChanged
uiapp.Application.DocumentChanged -= OnDocumentChanged


OUT = listId

Hi @urdiafa, I know its an old post but were you able to find a solution to this?

@Shambhavee @urdiafa ,

is this a “event” for you to see that transaction happend?

Hi @Draxl_Andreas ,

Thanks for replying, I should have made myself clear :sweat_smile:
I was trying to look for a way to use Application Events in IronPython, which in this case is DocumentChange Event so I can implement it on other events. Let me know if you have a solution to this. I see a lot of examples in C# but as I’m fairly new to Revit API as well as coding so I’m currently able to execute Revit API through python.

I’m basically facing the same issue as in this article:

and I’m trying to use DocumentOpening and DocumentOpened Events and see if suppressing these popups is possible.

I’m currently refering to this article to try and convert it to python:

Thanks in Advance!

Dynamo generally doesn’t work in a way which supports events to my knowledge.

It would probably be possible using an addin to load dynamo and run a script when an event is detected, but unless it’s an infrequent event it might cause issues or just slow the overall experience. At that point you’d likely just code the addin to run code after the event anyway.

Maybe look into pyRevit and its ‘hook’ system which enables scripts written in Python whilst detecting events.