Copy link to clipboard
Copied
Hi,
Is there a way to continue the execution of the script after showing the dialog window, without user interaction?
I'm working on a script that uses the .findGrep() function. With long documents it could take some time. I would like the user to know that the script is working and is not hang. But as the findGrep() is a single line, I cannot use the progress bar. I thought I show the dialog, with some statictext like "processing..." then change the text when the find command is done. But after the show() command, the dialog is waiting for interaction. I tried onShow, but it is called before the window is made visible, so it's not working for me.
A dialog-type window waits for you to click OK, then the script can continue. It's like InDesign doalog windows: while they're visible you can't do anything else.
What you need is a paletter-style window. They are like InDesign panels: while they're visible you can work on you document, and a script can do stuff while the paletter is displayed.
P.
Copy link to clipboard
Copied
Hi,
Could you please post your existing code?
Copy link to clipboard
Copied
Hi Charu,
Thank you for your reply, but my problem is that I do not really have an existing code - because I do not know, how to do it.
I have defined a new Window:
w = new Window("dialog");
with some static tex:
t = w.add("statictext", undefined, "Processing...");
then I show the dialog:
w.show();
And at this point I want to execute the
found = app.selection[0].findGrep();
command, and then, when it finishes, change the text:
t.text = found;
But the onShow would execute anything before actually showing the window, and after w.show(); the execution stops, and is waiting for any user interaction. My question is: is there a way around it?
Zsolt
Copy link to clipboard
Copied
I do not really have an existing code - because I do not know, how to do it.
Hi @JakabZs , The findGrep() method returns a single array of results—I don’t think you would need a progress bar, but if you wanted to loop thru a very long array, the progress increment could be add to the for loop.
Here my found variable is the result array:
//would gets every Foo
var found = getGrepSearch("Foo")
alert(found.length)
//returns the length of the search array
for (var i = 0; i < found.length; i++){
$.writeln(found[i])
//returns each item of the array e.g. [object Word]
};
/**
* Gets results of a grep search
* @ param text to search for
* @ return search results as an array
*/
function getGrepSearch(fp){
app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
app.findGrepPreferences.findWhat = fp;
//an array of search results
return app.activeDocument.findGrep()
}
If I wanted to change each array item, I could use the changeGrepPreferences changeTo property. This should be much faster than looping through the found array:
/**
* Document Grep find and change
* @ param f the find grep string
* @ param c the change grep string
* @ return void
*/
function grepSearch(f,c){
app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
app.findGrepPreferences.findWhat = f;
app.changeGrepPreferences.changeTo = c;
app.activeDocument.changeGrep( true )
}
Here the 128 changes happen instantly
Copy link to clipboard
Copied
Hi Rob,
Thank you for your answer, but I know how findGrep works. In this script I want to use it for counting purposes only, not changing, but in a several hundred page document even findGrep() can take a few seconds... I made a mistake in my code, I intended to write "t.text = found.length;"
Zsolt
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi Robert,
Thank you for your reply, but that's not the problem. I know how to make a progressbar, but if you have olny one line (i.e. findGrep() ), you cannot show the progress.
Copy link to clipboard
Copied
I'm not JS guy - but can't you use "progressbar way" anyway?
Show 50% as an indicator that there is something going on - and then when it finished - jump to 100% and "finished"?
Copy link to clipboard
Copied
That's my plan B...
Copy link to clipboard
Copied
A dialog-type window waits for you to click OK, then the script can continue. It's like InDesign doalog windows: while they're visible you can't do anything else.
What you need is a paletter-style window. They are like InDesign panels: while they're visible you can work on you document, and a script can do stuff while the paletter is displayed.
P.
Copy link to clipboard
Copied
Hi Peter,
Thank you very much. Indeed this is what I need! 🙂
I'll give try to the palette.
Thanks again
Zsolt