Copy link to clipboard
Copied
Is there a way to force an script to stop executing from CEP panel? For example in long loops:
my first thought was to make the loop in the CEP context and pass the index and the data in each loop to an extendscript method, so I can control the loop outside, but it seems to be a little cumbersome.
Is there a simpler aproach? I'm especially thinking about more complex processes with more loops and complexity layers
Copy link to clipboard
Copied
I don't think this is possible, unfortunately.
As you suggested, the only option is probably to do the loop in CEP and split the job into many small jsx executions. That's also what I do in Still Exporter, for example, to show a status update in the CEP panel while the images are exported.
Copy link to clipboard
Copied
I was also just thinking about it to make progress bars, although perhaps for that it would be easier to use the extendscript UI builtin tools.
Copy link to clipboard
Copied
You can make your function run async with "app.scheduleTask();" and during each loop check the global object if the execution should continue, for example:
if ($.["myscriptname"].continueRun === false) {
// break the loop here and cancel task
app.cancelTask(); //
}
Copy link to clipboard
Copied
It seems like an interesting approach. I'm going to give it a try and tell you if that worked. Thanks
Copy link to clipboard
Copied
Maybe not the best approach, but the way I managed to make it work is by creating stop.txt file next to the main extendscript file and when user runs functions from UI, it writes with fs and path modules to the txt file '0' which means 'don't stop', the through extendscript I added checkers that read the file and throw error if the stop.txt contains '1', error is taken care by trycatch
stop button in UI writes to stop.txt '1' which means 'stop'
Find more inspiration, events, and resources on the new Adobe Community
Explore Now