• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AE CC2017 terminate scheduleTask() on panel close

Explorer ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

Is there some way to terminate app.scheduleTask() when the window panel of the script it was started from is closed or not present (as the scheduler runs constantly in background until AE is closed...which is not good)?

TOPICS
Scripting

Views

3.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

Yes, save the returned taskIDs of each scheduleTask() and on your window's onClose() event, cancel them all with app.cancelTask() and pass in each taskID from your scheduled tasks, see more details on usage here:

http://docs.aenhancers.com/general/application/?highlight=scheduletask#app-canceltask

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Thanks for reply but sorry to inform you that onClose() does not work at least for me - tried several times before asking this (actually that was the exact reason why I am asking at all as quite interestingly I was trying to do the same you are advising me here (logically), haha - window.onClose() DOES NOT WORK IN CC2017)

This is how I am applying it that does not work - I run it as "dockable" panel/window via Window menu in AE CC2017:

//inside my .jsx file in "ScriptUI Panels"

var np = (this instanceof Panel) ? this : new Window("palette", "Navigator", undefined, {resizeable:true});

np.onClose = function()

{

   // just to test it works...which it isn't

    alert("Closing");

}

The reason I need this is that I have the panel as part of my workplace where it sits on the left side right to Timeline panel, so when I have a project that was saved with different workplace (that is without my panel) it ends up in error/crashing as it cannot find physical objects (listBox) that is normally created in my panel (because as we know app.scheduleTask() runs nonstop until one close AE...or finds a way how to terminate it using app.cancelTask() on the run once it detects the panel/window it was created in does not exist any longer: logically it should be window.onClose() which does not work in AE CC2017 as I said)

EDIT:

OK, only now I understood it is always created as panel this way not a window (just realized it going thru some other script).

So my updated question should look more like: how to have action upon closing the Panel - is there some equivalent to window.onClose()?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Yea you're right, onClose() doesn't seem to work with dockable Script UI panels only windows. You could try checking if the window is visible with window.visible, and if not then cancel the Task from inside the task function.

If you want more functionality for things like this, I definitely recommend looking into CEP panels if you haven't already. A bit more complicated, but offer way more possibilities.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Thanx for the advice, I am looking into CEP now but it is such a mess as for the explanation what it is or how to use it or even where to place the examples - place the sample inside EXTENSION folder of what? AE has no such folder (at least none I would know of, looking into Support Files folder inside AE CC2017 folder), so what the hack are they talking about?! Very messy to me indeed, unfortunately... 😞

EDIT:

Oh, so now I see it is some kind of separate Adobe application?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

OK, I kind of solved it indirectly: I am testing during every scheduleTask() cycle inside the called function with try/catch if there is still instance of the object (in my case ListBox) - if it throws error I know the dialog window was closed/is not present anymore (I just changed my mind and replaced canceling the task with "do nothing" instead as I need to run when there is the ListBox once again) BUT I still have one another issue which is Modal Dialog error coming into my way that is not catch by the try/catch: dose anyone know hot to get rid of the "Can not run a script while a modal dialog is waiting for response"?

But I see no modal dialogs - there is nothing awaiting of anything, that message even does not show up until I manually close my panel and reopen it!

And even stranger is the fact it only happens with a huge project(s) having like 850 active layers which take about 30 seconds to fully open, but with small projects there is no problem like this at all.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

To answer the first response:

It's generally not a good idea to constantly run scripts in your application as they can slow down user performance and you can run into issues like this. It's better to check for updated values with the user hovers/interacts with your tool.

To answer the second response:

CEP is an awesome framework, it's definitely more complicated than everything contained in a single script file like with Script UI, but you're still coding in Javascript/Extendscript for the most part, and now you can access Node.js and all the npm modules which are way faster than Extendscript and open up endless possibilities for your tool.

To get started, download the sample panel: Samples/AfterEffectsPanel at master · Adobe-CEP/Samples · GitHub

And follow the cookbook to get up and running: CEP-Resources/CEP 8.0 HTML Extension Cookbook.md at master · Adobe-CEP/CEP-Resources · GitHub

Basically, copy the extension to your global extension folder

  • Win(x86): C:\Program Files\Common Files\Adobe\CEP\extensions
  • Win(x64): C:\Program Files (x86)\Common Files\Adobe\CEP\extensions, and C:\Program Files\Common Files\Adobe\CEP\extensions (since CEP 6.1)
  • Mac: /Library/Application Support/Adobe/CEP/extensions

Enable PlayerDebugMode

  • Win: regedit > HKEY_CURRENT_USER/Software/Adobe/CSXS.8, then add a new entry PlayerDebugMode of type "string" with the value of "1".
  • Mac: In the terminal, type: defaults write com.adobe.CSXS.8 PlayerDebugMode 1 (The plist is also located at /Users/<username>/Library/Preferences/com.adobe.CSXS.8.plist)

And then launch AE, and start changing stuff and see how the example functions work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

No, not in this specific case - I understand you do not know purpose of my script as I did not mentioned yet what it does: it automatically checks main comp (activeItem) markers, get them and let you navigate thru timeline via clicking the specific marker in my panel (markers become buttons)...user do not have to click anything anywhere - script will do it for him automatically checking constantly (2sec) stat of the markers (not heavy computing at all), that is the main purpose like run it and forget it, it will do all for you, you just click the specific marker to go there, that's it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Gotcha, this question just came up recently. I believe the solution was to check the appStatus:

if(BridgeTalk.appStatus === "IDLE"){

    // Do Stuff

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Nah, still does not work for me:

#targetengine "session";

#include "Navigator"; //<--- actually another .jsx file just  without extension 😄

var checkTask = app.scheduleTask("if(BridgeTalk.appStatus === 'IDLE'){getActiveItemMarkers();}", 2000, true);

BTW does not Modal Dialog issue terminate immediately COMPLETELY WHOLE SCRIPT so there is not even chance to check anything as ti can not reach any statement as it is already terminated, hm? 😉

The whole script won't even start as soon as there is some Modal Dialog thus your code would not be executed: "Can not run a script while a modal dialog is waiting for response".

Or am I wrong about this? Cos if it is so then, I think solution to this Modal Dialog thing cannot be solved via script as any script is immediately terminated as soon as there is some Modal Dialog issue (ehm, talking/meaning specifically "perpetual" app.scheduleTask() which becomes automatically broken this way that is it won't continue once Modal Dialog issue is gone)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Strange, which version are you testing with and what dialog is causing the error? (I'm on AE 16.1.1 and testing with the Save Changes before Closing dialog but it's not throwing the error.)

I believe only certain functions cause that issue but not low-intensity checks like appStatus.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

  • AE 14.1.0.57 (CC2017.1)
  • there is no visible dialog that would causing it - that Modal Dialog error does not even show: my script simply does nothing, so I close its window (panel) and upon reopening it that error dialog shows up
  • this only happens with extremely huge project having lie 850+ active layers that opens for 30 seconds, any other "normal" (=small) project works just great as expected with my script
  • I still think that if the Modal Dialog is saying IT CANNOT RUN SCRIPT it means script as such, that is not a single line from the script is run thus it probably cannot be solved script-wise

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

So you're saying, you start AE, open your script, open a big project, your script fails silently, and when you re-launch it then you get the "Can not run a script while a modal dialog is waiting for response" error? If so, that's very strange. I've never got that error unless it was trying to do something during a dialog that just happened.

If you can delay any looping/scheduled operations till after the project is loaded I would do that, AE won't let you run scripts while you're opening a project.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

So you're saying, you start AE, open your script, open a big project, your script fails silently, and when you re-launch it then you get the "Can not run a script while a modal dialog is waiting for response" error? If so, that's very strange. I've never got that error unless it was trying to do something during a dialog that just happened.

EXACTLY THAT! 😞

Except that my script is already there as it is part of my active saved workplace...window/panel with ListBox is still there (it does not close) just the code does nothing. So I close the panel, reopen it and rest you already said yourself.

If you can delay any looping/scheduled operations till after the project is loaded I would do that, AE won't let you run scripts while you're opening a project.

Well, actually one of my first thoughts how to solve this was to find some way how to check if the project is fully opened and only then run the script but have no clue how to do that...but it would have to be done not via script, that is it should be done somehow else, but how? 😞

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

CEP Extension Panels have some events for this, I haven't tested them myself. There aren't any event equivalents in ExtendScript, I mean you can check if a project file is opened or not with var isOpened = app.project.file == null; but checking that during a load could also throw an error. Maybe have your script disable the loop once the project file is null, and then have the user manually re-enable it once they open a project. Or try some try/catch statements...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

None of that is usable:

it has to be "user-less" interface - no user interaction besides clicking desired marker position, if they need to enable somewhere first it breaks the reason I made that script in the first place as there already is at least one script where you have to manually click REFRESH and only then it updates, i wanted solution that would automatically updates itself all the time, I open my project an voila all is up and set s with that above mentioned script it does not remembered the previous state as soon as you reopen the project + it was unable getting comp markers, only layer. As I said I am extremely happy with my script as there is no such script available as far as I am concerned, if I would release it it would be the first of its kind out there 😉

As for the CEP: I gave up already, it is quite annoying, a lot of fiddling around just to set it up and have it running, bah, very bad, so no CEP solutions, please! 😄

+ it seems like you did not read what I wrote completely: I GUESS THIS CANNOT BE SOLVED VI SCRIPT ITSELF, Modal Dialog error BREAKS CODE AS WHOLE, it is simply stopped wherever it actually is, so it cannot evaluate anything at the very moment that error happens... 😞

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Well, your best bet then is to make a new post since this topic has deviated from the title and see if anyone else has ideas. Good luck

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Thank you for you effort helping me 😉

BTW just in case you'd be interested, this is the new post: AE CC2017 script terminates itself upon some hidden Modal Dialog error

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Hey, I just got success with something: using app.onError declared right after "#targetengine "session";" and BEFORE the app.scheduleTask() actually CATCH THAT ERROR MODAL DIALOG AND EVEN DISPLAYING IT (via alert(errString);)!!!!!!!

WOW, FINALLY: that is the first time we can really get hold on something usefull, now I am testing some options how to make it useful, like running function that would re-run my app.scheduleTask() and even disabling warning dialogs, we will see what will come from it (if anything at all, will let you know)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Glad you found a workaround. Definitely, do some testing cause you might be handling all script errors that way including ones from other people's scripts etc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

LATEST

In fact I stuck at the point of being able showing the error string in alert(), window and that's it for now, haha...maybe it is the late time here (Europe), maybe I should go to sleep...

Another thing I found out is that the error dialog is somehow suppressed or what, that is it is there but it did not show up until next time my panel is reopened: I undocked all the panels to see if it is somewhere behind them all but it is not, simply error occures but is not shown normally,strange isn't it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines