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
image

clr.AddReference(“RevitAPIUI”)
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Events import *
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB.Events import *
from Autodesk.Revit.DB import *
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference(“System.Windows.Forms”)
clr.AddReference(“System.Drawing”)
from System.Collections.Generic import List
import System
from System.Windows.Forms import *
from System.Drawing import *

def OnDocumentChanged (sender, e):
collection = e.GetAddedElementIds()
#listId.Add(collection.ElementAt(0))
listId.AddRange(e.GetAddedElementIds())

uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
listId = ListElementId

TransactionManager.Instance.EnsureInTransaction(doc)

uiapp.Application.DocumentChanged += OnDocumentChanged
uiapp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.DetailLine))
uiapp.Application.DocumentChanged -= OnDocumentChanged

TransactionManager.Instance.TransactionTaskDone()

OUT = listId