6 Replies Latest reply on Oct 9, 2018 1:12 PM by .-.--.--

    Deactivate Listener or Exit Script


      I have a script that starts up, and activates a document event listener using OnSelectionChange. I have set Scripting.DontExit = True, so this script is living a long time. I need to have a condition to deactivate the listener, somehow, or force the exiting of the script. Here's what it does, basically.


      Scripting.AttachEvents to Document

      onSelectionChange Listener Defined

        When someone changes the selection, call a sub that looks for selected components, and output property value to a message window tab

      <missing: a good way to exit the script, set the listener to do nothing, or clear the listener>


      What is among the cleanest ways to do this? I've considered starting another listener to look for another action, but then I have another listener going. I could have a enable/disable form, and maybe I will in the long run, but I'd like to keep this in a normal script. Could I create a separate script that overrides the previous listener somehow? Open to and looking for ideas!

        • 1. Re: Deactivate Listener or Exit Script

          We use Global Variables for this in AATK.


          Scripting.Globals("MyStat") = True



          1 of 1 people found this helpful
          • 2. Re: Deactivate Listener or Exit Script

            How do you toggle this variable mid-script? I take it your script event listener subroutine has an If statement that looks at that variable, and there is a way a user can do something to update that variable so that subroutine does nothing?


            And, as I think about it, I really want to exit the script at some point. I.e., I want that OnSelectionChange event listener in my script to be cleared, and the script to exit. The user can start up the script again, which would include the listener, the next time they need to.

            • 3. Re: Deactivate Listener or Exit Script

              I see that Kendall already responded so you can go with his suggestion but I wanted to share how I did this.  When I wanted my script to run for a long time then I didn't use Scripting.DontExit = True.  Instead, I added a for loop, which kept checking to see if viewdraw.exe process was running on the pc or not and if not, then I exited the for loop and script ran to completion i.e. script would get fired up by the way of scripts.ini and stay alive until viewdraw.exe was alive, otherwise script would also die once viewdraw.exe process was dead.

              • 4. Re: Deactivate Listener or Exit Script

                I should have added that in the for loop I was setting a variable that was something like iViewDrawRunning = 1, if ViewDraw.exe was valid.  Outside, the for loop I had an if statement such that if iViewDrawRunning = 1 then check for mouse left button click event and if that's true then do something...

                • 5. Re: Deactivate Listener or Exit Script

                  Hi, that's an interesting way of doing it. Do you have an example of how to do that from xPCB? How do you tell if another program is running?

                  • 6. Re: Deactivate Listener or Exit Script

                    This sounds like an ideal application for an IDE form (.efm file). Start it when you need it by any one of several methods, leave it running as long as you like (with no required Scripting.DontExit), then end it by closing the dialog box.