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

How to affect a PageItem within an OnClick handler

Community Beginner ,
Sep 22, 2015 Sep 22, 2015

Hi,

I'm trying to set the geometricBounds of a PageItem and that works fine until I do it within a button click handler, then nothing happens.

Code:

function createDialog(header, message, pageItem) {
     var dialog = new Window("dialog", header),
          textArea = dialog.add("statictext {preferredSize: [200, 100], properties: {multiline: true}}"),
          correctButton = dialog.add("button", undefined, "Correct");
     
     textArea.text = message;
     
     correctButton.onClick = function() {
          alert('Before');
          pageItem.geometricBounds = [1, 1, 8, 8];
          alert('After');
     }
     
     dialog.show()
}

Also, only the first alert pops up. 'After' is never shown.

Any ideas?

TOPICS
Scripting
251
Translate
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

Advisor , Sep 23, 2015 Sep 23, 2015

A dialog is a modal window. While it is active the script cannot "write" to indesign (it can read values from various objects, like those geometric bounds) but it cannot change them.
Solutions:
a) use a palette.

b) in the "onClick" handler record the geometric bounds, but only apply them once the dialog is closed:

  if (dialog.show()==1){pageItem.geometricBounds=myRecordedBounds;}

Translate
Advisor ,
Sep 23, 2015 Sep 23, 2015

A dialog is a modal window. While it is active the script cannot "write" to indesign (it can read values from various objects, like those geometric bounds) but it cannot change them.
Solutions:
a) use a palette.

b) in the "onClick" handler record the geometric bounds, but only apply them once the dialog is closed:

  if (dialog.show()==1){pageItem.geometricBounds=myRecordedBounds;}

Translate
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 ,
Sep 23, 2015 Sep 23, 2015
LATEST

That makes sense.

Thanks so much for all the help !

Translate
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