0

I use InDesign CS6. I wrote a javascript to add an option into menu: it first imports an XML in a document, then removes empty pages. As run, before it actually imports an XML file, it removes empty pages. So there aren't enough pages for the XML.

How to excute these 2 functions as wanted? Here is my program:

var menuItem = "XML";
var smaTitle1 = "Import XML";

var sma1 = app.scriptMenuActions.add(smaTitle1);

    // Add an Event Listener
    sma1.addEventListener(
        /*event type*/   'onInvoke',
        /*event handler*/ function(){
            importXML(xmlPath);
        }
    );
    sma1.addEventListener(
        /*event type*/   'afterInvoke',
        /*event handler*/ function(){
            // Remove empty pages
            alert("remove pages");
            removeEmptyPages();
        }
    );

function importXML(xmlPath){
 if (app.documents.length != 0){
        var myDocument = app.documents.item(0);  
         
        //import the entire XML structure in the document.
        var myXMLImportPreferences = myDocument.xmlImportPreferences;
        myXMLImportPreferences.allowTransform = false;
        myXMLImportPreferences.ignoreWhitespace = true;
        myXMLImportPreferences.removeUnmatchedExisting = false;
        myXMLImportPreferences.importStyle = XMLImportStyles.MERGE_IMPORT;
        myXMLImportPreferences.repeatTextElements = true;
        
        var path = new File(xmlPath);
        var file = path.openDlg("Importer XML", "XML:*.xml", false);
        if (file != null) {
            myDocument.importXML(file);                   
        }
 }
}

function removeEmptyPages(){
    ...
    // a loop to remove empty pages
    pages[i].remove();
    ...
}
wonder garance
  • 329
  • 1
  • 6
  • 14

1 Answers1

0

Why don't you just call your removeEmptyPages function at the end of your importXML function ?

function importXML(xmlPath) {
  …
  removeEmptyPages();
}
Jens
  • 8,423
  • 9
  • 58
  • 78
Loic
  • 2,173
  • 10
  • 13
  • I'd put removeEmptyPages(); in the function importXML(xmlPath), but it returned the same thing as my program before. Smart text reflow is already active. There are several linked placeholder frames in my template, then smart text reflow does't work – wonder garance Jan 20 '15 at 17:44