Skip to main content
Das Boomer
Known Participant
January 2, 2020
Answered

ScriptUI buttons don't allow pages to be added

  • January 2, 2020
  • 1 reply
  • 487 views

Greetings again,

 

I'm making good progress on my project, which I'll share once done. 

It'll take time, but with help I'll get through it.

 

The simple code to add a simple page works fine but if I wrap that code into a function called by the onClick event of a button it fails in ExtendScript (all latest).

 

Anyone can try the code below just to see if I'm nuts or what?

 

#target "InDesign"

var dialog = new Window("dialog"); 
    dialog.text = "Dialog"; 
    dialog.orientation = "column"; 
    dialog.alignChildren = ["center","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

var btn = dialog.add("button", undefined, undefined, {name: "btn"}); 
    btn.text = "No page for you"; 

var doc;
var pages;
app.documentPreferences.properties = {pageWidth:1.625, pageHeight:9.25}
doc = app.documents.add();

function add1page(){ pages = app.activeDocument.pages.add();}

btn.onClick = function() {add1page();};
dialog.show();
main();

function main(){}

 

Thank you kindly, and also, of course, Health and Happiness in this new year! 🙂

 

Antoine

 

This topic has been closed for replies.
Correct answer Manan Joshi

Hi Antoine,

 

The issue that i see is that you have the window type of your UI as dialog and this will create a modal doalog. Modal dialog would not allow any change in the document and that must be causing the code to fail.

If you change the type to a non modal palette it should work. Do the following change

 

var dialog = new Window("palette"); //Change the dialog type to palette

 

To make the dialog appear, put the following line on the top of your code after the #target "InDesign". This will create a persistent engine for your code to run

 

#targetengine "myEngine"

 

 

-Manan

1 reply

Manan JoshiCommunity ExpertCorrect answer
Community Expert
January 2, 2020

Hi Antoine,

 

The issue that i see is that you have the window type of your UI as dialog and this will create a modal doalog. Modal dialog would not allow any change in the document and that must be causing the code to fail.

If you change the type to a non modal palette it should work. Do the following change

 

var dialog = new Window("palette"); //Change the dialog type to palette

 

To make the dialog appear, put the following line on the top of your code after the #target "InDesign". This will create a persistent engine for your code to run

 

#targetengine "myEngine"

 

 

-Manan

-Manan
Das Boomer
Known Participant
January 2, 2020

Thank you kindly Manan! It worked.