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

InDesign script executing after dialog.show()

Community Beginner ,
Jun 06, 2023 Jun 06, 2023

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.

 

TOPICS
How to , Performance , Scripting , UXP Scripting

Views

665

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

correct answers 1 Correct answer

Community Expert , Jun 11, 2023 Jun 11, 2023

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.

Votes

Translate

Translate
Community Expert ,
Jun 08, 2023 Jun 08, 2023

Copy link to clipboard

Copied

Hi,

Could you please post your existing code?

Best regards

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 Beginner ,
Jun 09, 2023 Jun 09, 2023

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

 

 

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 ,
Jun 11, 2023 Jun 11, 2023

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()
}

 

 

 

 

 

Screen Shot 28.png

 

 

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

Screen Shot 30.png

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 Beginner ,
Jun 11, 2023 Jun 11, 2023

Copy link to clipboard

Copied

LATEST

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

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 ,
Jun 08, 2023 Jun 08, 2023

Copy link to clipboard

Copied

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 Beginner ,
Jun 09, 2023 Jun 09, 2023

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.

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 ,
Jun 09, 2023 Jun 09, 2023

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"?

 

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 Beginner ,
Jun 09, 2023 Jun 09, 2023

Copy link to clipboard

Copied

That's my plan B...

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 ,
Jun 11, 2023 Jun 11, 2023

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.

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 Beginner ,
Jun 11, 2023 Jun 11, 2023

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

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