Script question: exit handlers and how to trap the Esc key?

 From:  Larry Fahnoe (FAHNOE)
9918.9 In reply to 9918.7 
Hi Michael,

In case it is relevant, or maybe just a confirmation of your thought about the v4 Esc interrupt mechanism, here is some additional data.

My script uses a 2-stage process to create multiple leaders with coordinate values and as such it makes use of the allowNestedCancel() feature. The desired behavior around Esc/Cancel is to allow more granular cancellations rather than an immediate complete cancellation of the command. The UI Cancel button is working as desired and allows the granular cancellations but the Esc key does not. When the Esc key is pressed in the inner function it triggers a cascade of cancelbutton/cancel events in the same fashion as without allowNestedCancel() & thus an immediate complete cancellation of the command.

It is interesting that without allowNestedCancel() the Esc key throws an exception but with allowNestedCancel() it does not, but in either case the Esc triggers the cascade of cancelbutton/cancel events.

I added some logging with timing data to better understand what was happening and the following log snippets attempt to illustrate the difference between the Cancel button and Esc key. The >> indicates what I did with the UI

code:
     With pointpicker.allowNestedCancel()

     Test using Cancel button (requires 3 clicks on Cancel to exit
     command, desired behavior)
     >> Click on object
        6465ms: doCoordinates() event: finished
     >> Draw out leader, wait, click on Cancel
     >> Leader disappears, Pick leader arrow tip is shown
        10149ms: trapEsc() canceled: cancelbutton
        10149ms: coordinateLeader() event: cancel
     >> Wait, click on Cancel
     >> Pick next leader point is shown
        16373ms: trapEsc() canceled: cancelbutton
        16373ms: doCoordinates() event: cancel
     >> Wait, click on Cancel
        23072ms: trapEsc() canceled: cancelbutton
        23072ms: coordinateLeader() event: cancel

     Test using Escape key (first Escape causes command to exit)
     >> Click on object
        3465ms: doCoordinates() event: finished
     >> Draw out leader, then press Esc
        5876ms: trapEsc() canceled: escape
        5876ms: coordinateLeader() event: cancel
        5911ms: trapEsc() canceled: cancelbutton
        5911ms: doCoordinates() event: cancel
        5943ms: trapEsc() canceled: cancelbutton
        5943ms: coordinateLeader() event: cancel

     Without pointpicker.allowNestedCancel()

     Test using Escape key (first Escape causes command to exit)
     >> Click on object
        4989ms: doCoordinates() event: finished
     >> Draw out leader, then press Esc
        8470ms: trapEsc() caught
        8470ms: coordinateLeader() event: cancel
        8505ms: trapEsc() canceled: cancelbutton
        8505ms: doCoordinates() event: cancel
        8541ms: trapEsc() canceled: cancelbutton
        8541ms: coordinateLeader() event: cancel


Code attached if helpful, otherwise I'll continue to look forward to the next beta.

--Larry

EDITED: 6 Jul 2021 by FAHNOE