Page 1 of 1

[SOLVED] InDesign file generation and closing issues

Posted: Fri Nov 15, 2013 4:49 pm
by loicaigon
Hi,



I am trying to generate indesign documents on the fly based on a xml input.



To get Switch to run InDesign module, it seems I have to use a custom open script in order to open a dummy document (I don't need it really).



So later my script opens an indt template, populate some data, export files…It also closes the newly created document.



Problem is, the dummy document remains unclosed. And if I explicitely ask for its closing, InDesign actually closes it, but Switch returns an error.



What is teh way for running the InDesign configurator with no InDesign files as input ?



Thanks in advance,



Loic



/////////////////////////////////////////////////



It appears I was doing things wrong. I was executing most of my script in the "open" area of the InDesign Script configurator. I moved the main script to the "execute" area meanwhile keeping open for opening my dummy document.



Everything is now ok. Hope that may help someone.

[SOLVED] InDesign file generation and closing issues

Posted: Thu Feb 20, 2014 12:18 am
by neecerp
Hello!

Hey....I am trying to do what you did. I use xml and want to poplulate an InDD template (using tags) with the xml content. The part I am having trouble with is how to get the javascript to pick up whatever the next xml is that comes in to my Switch flow.



In other words...how do I make the xml it reads from a variable rather than a static file I am pointed to on the desktop....does that make sense? here is what I have now.....



( File("~/Desktop/N_SSI_TEST_2820.xml") needs to be any incoming xml with any name.....



Any chance you would be willing to share your javascript, flow or both?







main ()



function main () {

// create a path for a file object

var curFile = File ( "~/Desktop/xml.indt" );

// check if the file exists

if (!curFile.exists) {

alert ( "no template!" );

exit();

}

// open the file

var curDoc = app.open( curFile );

// create a new file object

var inddFile = new File ( curFile.parent + "/xml.indd" );

// save the file

curDoc.save( inddFile );



//XML import

curDoc.importXML( File("~/Desktop/N_SSI_TEST_2820.xml") );

// root-element

var root = curDoc.xmlElements[0];

// do your xml stuff, e.g.

var category = root.xmlElements[0]; // for more categories it needs a loop

var product1 = category.xmlElements.itemByName('productname');





}


[SOLVED] InDesign file generation and closing issues

Posted: Thu Feb 20, 2014 9:47 am
by loicaigon
Hi,



If your job is a XML file and you want it injected in a InDesign file, you have to work at two levels.



1) In the "open" section of InDesign configurator, use a script to open your indesign template



2) In the command section, call your main script. All you have to do is to use the "$infile" reference rather thant a static url reference.



So in your case :



//JS FILE for opening template



openTemplate() {

var curFile = File ( "~/Desktop/xml.indt" );

var curDoc = app.open( curFile );

}



openTemplate();



//Note that you can choos to work in a more dynamic way using $arg1



var curFile = File ($arg1);



where $arg1 is an argumnt you defined as a script pârameter in Switch (here you template url).





//COMMAND JS FILE





main ()



function main () {

//XML import

//$doc is the reference to the active document in the switch context

//$infile is the reference to the file you passed within the flow (your xml)

$doc.importXML( File($infile) );

// root-element

var root = curDoc.xmlElements[0];

// do your xml stuff, e.g.

var category = root.xmlElements[0]; // for more categories it needs a loop

var product1 = category.xmlElements.itemByName('productname');



}



Hope that helps,



Loic

http://www.loicaigon.com