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

Simple script, but cannot handle the request(dialog or alert is active

Explorer ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

Hello,

I try this simple script.

Extendscript returns error "cannot handle the request because a modal dialog or alert is active".

"w.close()" seems not working.

Don't understand why, can somebody explain me please?

#target "InDesign"

#targetengine "main"

win();

function win() {

   

    var w = new Window ("palette", "UI");

    var myBtn = w.add ("button", undefined, "nouveau document");

    myBtn.onClick = function() {

        w.close();

        newDoc();

    }

    w.show ();  

}

function newDoc (){

   

    var doc = app.documents.add(true);

    with(doc.documentPreferences){

        pageHeight = "2000mm";

        pageWidth = "2000mm";

        pageOrientation = PageOrientation.landscape;

        pagesPerDocument = 1;

    }

}

TOPICS
Scripting

Views

1.5K

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

People's Champ , Feb 16, 2017 Feb 16, 2017

Because the dialog isn't really close yet.

You have to execute your routine this way:

win(); 

 

function win() {  

     

    var w = new Window ("dialog", "UI");  

    var myBtn = w.add ("button", undefined, "nouveau document");  

    myBtn.onClick = function() { 

        w.close(1);

    } 

  var myBtn = w.add ("button", undefined, "Annuler");  

    myBtn.onClick = function() { 

        w.close(0);

    } 

   if (  w.show ()==1 )   newDoc();      

 

function newDoc (){ 

     

    var doc = app.d

...

Votes

Translate

Translate
Explorer ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

It works, when using #targetengine "session" and creating 'palette' instead of 'dialog'.

I don't really understand why it didn't work before.

If somebody can explain me…

Thanks.

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
Guide ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

Hi jjrger,

The reason your original script didn't work is exactly what ExtendScript told you: "cannot handle the request because a modal dialog or alert is active". In other words, DOM commands—such as app.documents.add(true)—are unavailable from a modal dialog. You need to either close the dialog before sending the command, or to base your code on a non-modal window ('palette' or 'window' type.)

@+

Marc

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 ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

Thank you Marc,

But the script ask w.close() before sending the command. That why I don't understand. Is there a timing explanation??

Jimmy

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
People's Champ ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

Because the dialog isn't really close yet.

You have to execute your routine this way:

win(); 

 

function win() {  

     

    var w = new Window ("dialog", "UI");  

    var myBtn = w.add ("button", undefined, "nouveau document");  

    myBtn.onClick = function() { 

        w.close(1);

    } 

  var myBtn = w.add ("button", undefined, "Annuler");  

    myBtn.onClick = function() { 

        w.close(0);

    } 

   if (  w.show ()==1 )   newDoc();      

 

function newDoc (){ 

     

    var doc = app.documents.add(true); 

    with(doc.documentPreferences){ 

        pageHeight = "2000mm"; 

        pageWidth = "2000mm"; 

        pageOrientation = PageOrientation.landscape; 

        pagesPerDocument = 1; 

    } 

}  

Have a look at ScriptUI for Dummies from Peter Karhel:

http://www.kahrel.plus.com/indesign/scriptui.html

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
Guide ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

To complement Loïc's answer, I think important to mention that myWindow.close() is something of a ScriptUI command which notifies an event through the Window component. At this point, other events may still need to be handled (e.g. onClose, onDeactivate…).

So myWindow.close() does not result in myWindow.active==false. In fact the window remains active as long as its inner event loop is running. The rule is, you can't have your modal window in a non-active state from within any event handler. You need to exit the ScriptUI layer, which is guaranteed once w.show() has returned.

@+

Marc

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 ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

LATEST

Thanks to you both for these precisions.

The uses of palette, dialog, and the event timing of window close are more clear for me.

Merci beaucoup!

Jim

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