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

How to detect change of document ?

Community Expert ,
Apr 28, 2016 Apr 28, 2016

Copy link to clipboard

Copied

Dear friends and experts,

It seems obvious that with my new project I have opened the box of Pandora...

Palettes stay open even when setting a new cursor location, hence I use this for my dialogue.

But the user can also switch to another document while the palette is open.

Currently I have a button Refresh and the user is urged to use it after switching to another document. The function behind is to analyse the newly entered document and define global variables, update the dialogue.

How could I detect the switch of the document ? I have not found something like onDocumentChange.

(In the current script a check for changed document name is in the btnRefresh.onClick function to avoid irrelevant work).

Thank You for any ideas.

Klaus

TOPICS
Scripting

Views

986

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

Enthusiast , Apr 29, 2016 Apr 29, 2016

Hi Klaus,

this version of your script works fine:

Just remove some "var" in winPal - dialog.

Remove "winPal.show ()" in function Notify

give a little more space to st1.

   #target framemaker 

    Notification (Constants.FA_Note_PostActiveDocChange, true);   

    var globalValue = app.ActiveDoc.Name; 

    var winPal = new Window ("palette", "Simple Palette", undefined); 

      

    SimplePalette (globalValue); 

     

    function SimplePalette (outerParm) { 

       innerParm = "none"; 

       buttonO

...

Votes

Translate

Translate
Community Expert ,
Apr 28, 2016 Apr 28, 2016

Copy link to clipboard

Copied

Hi Klaus,

There is a notification you can use: Constants.FA_Note_PostActiveDocChange

You set it up something like this in your script:

// Set the notification for after the active document changes.

Notification (Constants.FA_Note_PostActiveDocChange, true);

// Built-in function that is called when a event is triggered.

function Notify (note, object, sparam, iparam) {

  

    // Handle the event triggered after the active document changes.

    switch (note) {

      

        case Constants.FA_Note_PostActiveDocChange:

            // Update your dialog box here.

            break;

    }

}

-Rick

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 ,
Apr 29, 2016 Apr 29, 2016

Copy link to clipboard

Copied

Thanks You, Rick

In theory I knew that from the ExtendScript documentation - but does not know how to implement.

Encouraged by your post I tried this:

#target framemaker
Notification (Constants.FA_Note_PostActiveDocChange, true); 

var globalValue = app.ActiveDoc.Name;
var winPal = new Window ("palette", "Simple Palette", undefined);

SimplePalette (globalValue);

function SimplePalette (outerParm) {
  var innerParm = "none";
  var buttonOuter = winPal.add ("button", undefined, "Outer");
  var buttonInner = winPal.add ("button", undefined, "Inner");
  var st0 = winPal.add ("statictext", undefined, "st= " + innerParm);
      st0.preferredSize.width = 300;
  var st1 = winPal.add ("statictext", undefined, "Button clicked: " + innerParm);

  buttonOuter.onClick = function () {
    st1.text = "Button clicked: Outer";
  }

  buttonInner.onClick = function () {
    st1.text = "Button clicked: Inner";
    st0.text = outerParm;                                // this changes the display
  }

  winPal.show ();
}

function Notify (note, object, sparam, iparam) { 
// Handle the event triggered after the active document changes.
$.br(true);
  switch (note) { 
    case Constants.FA_Note_PostActiveDocChange: 
      // Update your dialog box here.
      winPal.st1.text = "Current document is " + object.Name ;
      winPal.show ();
      break; 
  } 
}

I have two documents open when I start the script. Clicking button Inner places the current document name.

When switching the document I expected to run into the breakpoint - but nothing happens.

Is function Notify at a wrong place - and may it have a different name?

Thank You for clarifying this.

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
Enthusiast ,
Apr 29, 2016 Apr 29, 2016

Copy link to clipboard

Copied

Hi Klaus,

this version of your script works fine:

Just remove some "var" in winPal - dialog.

Remove "winPal.show ()" in function Notify

give a little more space to st1.

   #target framemaker 

    Notification (Constants.FA_Note_PostActiveDocChange, true);   

    var globalValue = app.ActiveDoc.Name; 

    var winPal = new Window ("palette", "Simple Palette", undefined); 

      

    SimplePalette (globalValue); 

     

    function SimplePalette (outerParm) { 

       innerParm = "none"; 

       buttonOuter = winPal.add ("button", undefined, "Outer"); 

       buttonInner = winPal.add ("button", undefined, "Inner"); 

       st0 = winPal.add ("statictext", undefined, "st= " + innerParm); 

       st0.preferredSize.width = 300; 

       st1 = winPal.add ("statictext", undefined, "Button clicked: " + innerParm); 

      st1.preferredSize.width = 300;

      buttonOuter.onClick = function () { 

        st1.text = "Button clicked: Outer"; 

      } 

     

      buttonInner.onClick = function () { 

        st1.text = "Button clicked: Inner"; 

        st0.text = outerParm;                                // this changes the display 

      } 

     

      winPal.show (); 

    } 

     

    function Notify (note, object, sparam, iparam) {   

    // Handle the event triggered after the active document changes. 

    $.bp(true);  // here was a type : $.br(true)

      switch (note) {   

        case Constants.FA_Note_PostActiveDocChange:   

            {

          // Update your dialog box here.  

          st1.text = "Current document is " + object.Name ;  

          break;   

          }

      }   

    }  

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 ,
Apr 30, 2016 Apr 30, 2016

Copy link to clipboard

Copied

LATEST

Thanks, Klaus, yes it really does what it should.

I forgot to remove the var after moving the window declaration out of the dialog function

But it is impossible to debug function Notify:

  1. Just running the script with F5 in ESTK does not honour the breakpoint in line 30.
  2. Using step into (F11) suddenly creates a new script file when i reach line 2.
  3. The new script file contains this highlighted line:
    $.fileName
  4. Stepping further creates another new script file containing this highlighted line:
    (new File("/e/_DDDprojects/FM-calc/test-scripts/OnDocumentChangeTest2.jsx")).fsName
  5. Stepping further creates another new script file containing this highlighted line:
    $.line
  6. Stepping further eventually brings me back into my script to line 3.
  7. More steps with F11 eventually displays the dialog.
  8. Klicking buttuns do what they should
  9. Changing the document displays the new document name in the dialogue.
    But the breakpoint (ah, there was typo again) is not honoured. No return into ESTK.

It seems that I have to live with this behaviour - maybe an alert would provide information if needed.

Thank You for your corrections which finally led to a working script!

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