App-closing hook doesnt work

Wondering if anybody has had any luck with the app-closing hook or any other suggested workarounds
found this note in notion as well - suggesting it might not be working as expected

I’ve never used that hook, so I don’t know if it works or not. But for a workaround, you can try subscribing manually in the startup.py script of your extension. That may give better results, because you’re interfacing directly with the Revit Api event instead of pyRevits hook api.

Do you have a sample? - for some reason, my event handler is not picking up

this is how my code looks currently

def appcloselogger(sender,args,__rvt__):
    log_type = 'Application Closing'
    app_version = "Revit " + str(app.VersionNumber)
    test_string = '{},{} \n'.format(log_type,app_version)
    file_name = 'file.txt'
    with open(file_name,'a+') as f:
        f.write(test_string )


__revit__.ApplicationClosing += EventHandler[UI.Events.ApplicationClosingEventArgs](appcloselogger)

Your issue with that code is probably because you have too many arguments.

I tested this code and it worked fine.

def appcloselogger(sender, args):
    import os
    desktop_path = os.path.expanduser("~\\Desktop")
    test_path = os.path.join(desktop_path, 'test')
    os.mkdir(test_path)


__revit__.ApplicationClosing += appcloselogger
2 Likes

man - that was it - simplicity is what i needed :slight_smile: