Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 93817

How to 'import xml' in my script

$
0
0

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[i].label="S_TF";        }     }




var myDoc=app.activeDocument;
var mspreads=myDoc.masterSpreads;
for (i=0;i<mspreads.length;i++)
{
if(mspreads[i].textFrames.length>1)
{    var txfmlength=mspreads[i].textFrames;    for (j=0;j<txfmlength.length;j++)    {        if(txfmlength[j].nextTextFrame!=null)        {txfmlength[j].label="S_TF";}        if(txfmlength[j].previousTextFrame!=null)        {txfmlength[j].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


Viewing all articles
Browse latest Browse all 93817

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>