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

detect xml structure changes in Indesign

Explorer ,
Jun 08, 2018 Jun 08, 2018

Copy link to clipboard

Copied

Hi,

I have to detect a change in the xml structure of my Indesign document (like node deleted, moved and so on).

How can I do that in a cep extension ?

I haven't seen any event for that in Indesign

Thanks in advance

TOPICS
Scripting

Views

582

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 , Jun 10, 2018 Jun 10, 2018

Well, I am guessing that you should either listen at AFTER_SELECTION_CHANGED EVENT or IDLE_EVENT and constantly monitor structural changes.

AFTER_SELECTION_CHANGED may be preferable but could suffer from latencies dues to User UI manipulation (the event will be fired only when user will select anything else or deselect everything).

IDLE_EVENT will be more "realtime" but could suffer from performance issues as xml files would be generated a lot of times per second.

Of course one can argue that expor

...

Votes

Translate

Translate
People's Champ ,
Jun 10, 2018 Jun 10, 2018

Copy link to clipboard

Copied

Well, I am guessing that you should either listen at AFTER_SELECTION_CHANGED EVENT or IDLE_EVENT and constantly monitor structural changes.

AFTER_SELECTION_CHANGED may be preferable but could suffer from latencies dues to User UI manipulation (the event will be fired only when user will select anything else or deselect everything).

IDLE_EVENT will be more "realtime" but could suffer from performance issues as xml files would be generated a lot of times per second.

Of course one can argue that exporting XML could be unnecessary but I think this methods is better than looping through the DOM (but that's personal opinion and also a bit of measure)

//inDesign.jsx

#targetengine "xmlChanges"

var main = function(){

var evName = "onAfterSelectionChangedEvent",

ev = app.eventListeners.itemByName (evName),

db = {},

    externalObjectName = "PlugPlugExternalObject",

    mylib = new ExternalObject( "lib:" + externalObjectName ),

    eventObj = new CSXSEvent(),

evHandler = function(evt) {

var doc = app.properties.activeDocument, docId, docStr, xmlFile;

if ( !doc ) {

db = {};

return;

};

docId = doc.id;

xmlFile = File ( Folder.temp+"/"+docId+".xml" );

doc.exportFile ( ExportFormat.XML, xmlFile );

if ( !xmlFile.exists ) return;

if ( !xmlFile.open('r') ) return;

docStr = XML ( xmlFile.read() );

xmlFile.close();

xmlFile.remove();

if  ( !db[docId] ) {

db[docId] = docStr;

            eventObj.type="xmlChanged";

            eventObj.data = "";

            eventObj.dispatch();

}

else {

if ( docStr!= db[docId] ) {

                eventObj.type="xmlChanged";

                eventObj.data = "Something changed !";

                eventObj.dispatch();

db[docId] = docStr;

}

            else {

                eventObj.type="xmlChanged";

                eventObj.data = "Nothing new under the sun !";

                eventObj.dispatch();

            }

}

       

       

};

   

   

    //="blahblah";

if  ( !ev.isValid ) app.eventListeners.add("afterSelectionChanged",evHandler).name = evName;

   

    eventObj.type="xmlChanged";

    eventObj.data = "Nothing new under the sun !";

    eventObj.dispatch();

}

main();

In main.js

$(function() {

    var csInterface = new CSInterface();

    csInterface.addEventListener ( "xmlChanged", function(evt) {

         $("#result").text ( evt.data );

    });

   

});

in html

<body>

      <p>Listening at xml changes…</p>

      <p id="result"></p>

     

      <button onclick="window.location.reload()">RL</button>

     

  </body>

And voilà :

Capture d’écran 2018-06-10 à 17.12.04.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
Explorer ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

Thanks for you answer, it works well !

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

Copy link to clipboard

Copied

LATEST

glad it helped…

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