OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Can't unsubscribe from an event in Revit

  • Thread starter Thread starter Mi-liali
  • Start date Start date
M

Mi-liali

Guest
I'm trying to set up the UI to automatically clear elements when I subscribe to an event DialogBoxShowing. I can't unsubscribe from it and the replacement of user actions continues even when the code isn't executing.

I don't have enough experience to find the error. Maybe someone has encountered this. Thank you in advance!

Code:
def call_purge():

    def import_replacement(sender, args):

        print('5')
        print(type(args))

        if args.DialogId == 'Dialog_Revit_PurgeUnusedTree':
                args.OverrideResult(1)

    """Call Revit "Purge Unused" after completion."""
    # commandId = \
    #     UI.RevitCommandId.LookupPostableCommandId(
    #         UI.PostableCommand.PurgeUnused
    #         )

    commandId = UI.RevitCommandId.LookupCommandId("ID_PURGE_UNUSED")


    try:
        __revit__.DialogBoxShowing += framework.EventHandler[UI.Events.DialogBoxShowingEventArgs](import_replacement)
        __revit__.PostCommand(commandId)
        __revit__.DialogBoxShowing -= framework.EventHandler[UI.Events.DialogBoxShowingEventArgs](import_replacement) 
    except:
        print(traceback.format_exc())

        
if __name__ == '__main__':
    call_purge()
    print('-' * 50)
    print('Script is finished.')

I found a method in the articles where these functions were separated into a separate class, but this also did not work
<p>I'm trying to set up the UI to automatically clear elements when I subscribe to an event DialogBoxShowing. I can't unsubscribe from it and the replacement of user actions continues even when the code isn't executing.</p>
<p>I don't have enough experience to find the error. Maybe someone has encountered this.
Thank you in advance!</p>
<pre><code>def call_purge():

def import_replacement(sender, args):

print('5')
print(type(args))

if args.DialogId == 'Dialog_Revit_PurgeUnusedTree':
args.OverrideResult(1)

"""Call Revit "Purge Unused" after completion."""
# commandId = \
# UI.RevitCommandId.LookupPostableCommandId(
# UI.PostableCommand.PurgeUnused
# )

commandId = UI.RevitCommandId.LookupCommandId("ID_PURGE_UNUSED")


try:
__revit__.DialogBoxShowing += framework.EventHandler[UI.Events.DialogBoxShowingEventArgs](import_replacement)
__revit__.PostCommand(commandId)
__revit__.DialogBoxShowing -= framework.EventHandler[UI.Events.DialogBoxShowingEventArgs](import_replacement)
except:
print(traceback.format_exc())


if __name__ == '__main__':
call_purge()
print('-' * 50)
print('Script is finished.')
</code></pre>
<p>I found a method in the articles where these functions were separated into a separate class, but this also did not work</p>
 

Latest posts

Top