Skip to main content
Inspiring
July 26, 2014
Question

How to 'import xml' in my script

  • July 26, 2014
  • 0 replies
  • 427 views

Hi All,

Below "Script 1" is working fine, now I want to call the '.xml' file which was placed in Template folder(see script code).

How to import xml in 'New.indd' file("Line 27:-->var source = File(path + '/New.indd')".

Please add import xml code in 'Script 1"

Script 1:

var path = Folder.selectDialog ("Select folder");

if(path==null)

{

exit();

}

 

var files = path.getFiles(/\.(indd?|indt?)$/i);

if(files==0)  

{

  alert("There is no 'indd'/'indt' file in your folder");

  exit();

}

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

try

{

myDocument = app.open(new File(files));

MasterpageScriptLabel();

TableCellStyleCreation();

myDocument.save(new File(path + "/New.indd"));

var folder = new Folder(path + '/Updated_Folder');

folder.create();

myDocument.close();

var source = File(path + '/New.indd');

var dest = new File(folder + '/New.indd');

source.copy(dest);

source.remove();

}

catch(e)

{

alert ("Your folder permissible only one file of 'INDD' or 'INDT' file");

exit();

}

      

function MasterpageScriptLabel()

{

var myDoc=app.activeDocument;

var myXMLElement=myDoc.xmlElements[0];

if(myXMLElement.isValid)

{

    var myParentStory=myXMLElement.parentStory;

    var myTextContainers=myParentStory.textContainers;

       

    for(var i=0;i<myTextContainers.length;i++)

    {

        myTextContainers.label="S_TF";

        }

     }

var myDoc=app.activeDocument;

var mspreads=myDoc.masterSpreads;

for (i=0;i<mspreads.length;i++)

{

if(mspreads.textFrames.length>1)

{

    var txfmlength=mspreads.textFrames;

    for (j=0;j<txfmlength.length;j++)

    {

        if(txfmlength.nextTextFrame!=null)

        {txfmlength.label="S_TF";}

        if(txfmlength.previousTextFrame!=null)

        {txfmlength.label="S_TF";}

        }

    }

}

}

function TableCellStyleCreation()

{

    var cestyle = myDocument.cellStyles;

    var array = ["TBL_COLH", "TBL_BODY"];

    var i = array.length;

    while(i--)

    {

            try{

                var style = myDocument.cellStyles.add();

                style.name = array[i++];

            }

            catch(e)

            {

                style.remove();

                alert("'" + array[i-1] + "'"+ " Already exists in the document.")

                }

            i--;

        }

}

main();

function main(){

      var progress_win = new Window ("palette");

var progress = progress_bar(progress_win, 2, 'Processing ... Completed');

    delay(1);

      progress.value = progress.value+1;

    delay(1);

    progress.parent.close();

    }

// delay function found here

//found here http://www.wer-weiss-was.de/theme157/article1143593.html

  function delay(prmSec){

  prmSec *= 1000;

  var eDate = null;

  var eMsec = 0;

  var sDate = new Date();

  var sMsec = sDate.getTime();

  do {

  eDate = new Date();

  eMsec = eDate.getTime();

  } while ((eMsec-sMsec)<prmSec);

  }

/**

* Taken from ScriptUI by Peter Kahrel

*

* @param  {Palette} w    the palette the progress is shown on

* @param  {[type]} stop [description]

* @return {[type]}      [description]

*/

function progress_bar (w, stop, labeltext) {

var txt = w.add('statictext',undefined,labeltext);

var pbar = w.add ("progressbar", undefined, 1, stop);

pbar.preferredSize = [300,20];

w.show ();

return pbar;

}

by

hasvi

This topic has been closed for replies.