duplicate pages and move to another file
Hi all,
I have a script which needs some work, any pointers or resources would be great!
It works for short files but anything larger and the script stops as it starts adding the pages to the IDMl file instead of the "doc".
I'm not sure why this is happening.
// Opens a folder browser dialog box, where you can choose a folder with the file you want to import.
// The chosen folder is stored inside 'targetFolder'.
// Note: In this script, files will be imported in the order they appear in the folder!
// Stores a reference to the currently open document into which we will import the files (this should be the English master).
importTranslations ();
// Stores the IDML files inside 'fileList'
function importTranslations () { // Create a function which will import the files.
var doc = app.activeDocument,
targetFolder = Folder.selectDialog ("Select a folder with idml translations \r*files must be in the order you want them to be imported*\rFR\rDE\rIT\rES\rNO\rRU\rTR",undefined, "Select a folder"),
TL,
TLpages,
fileList = [];
if ( targetFolder!= null ) {
var fileList = targetFolder.getFiles("*.idml");
} else {
exit(0);
}
for ( var i = 0; i < fileList.length; i++ ) { // Loop through the IDML files inside 'fileList'.
TL = fileList; // Store each file in a variable called 'TL'.
app.open( TL ); // open each file
TLpages = app.activeDocument.pages.everyItem().getElements(); // Store the open IDML file pages inside 'TLpages'.
for ( var j = 0; j <TLpages.length; j++ ) { // Loop through the pages
switch ( fileList ) {
case fileList[0]:
TLpages
break;
case fileList[1]:
TLpages
break;
case fileList[2]:
TLpages
break;
case fileList[3]:
TLpages
break;
case fileList[4]:
TLpages
break;
case fileList[5]:
TLpages
break;
case fileList[6]:
TLpages
break;
}
TLpages
if ( doc.pages.length % 2 == 1 ) { // Add a spread if the number of pages in the main doc is odd
doc.spreads.add( { allowPageShuffle: true } ); //Allow the pages to shuffle
TLpages
} else { TLpages
};
if ( doc.sections.length > 1 ) { // If there are more than 1 section then remove the excess sections.
doc.sections.itemByRange(1, -1 ).remove();
};
}
app.activeDocument.close(SaveOptions.NO); // Close the IDML and don't save.
}
var pages = app.activeDocument.pages.everyItem().getElements();
for ( i = 0; i<pages.length; i++ ) {
if (pages.pageItems.length==0) {
pages.remove();
}
} //delete empty pages
alert ("Files successfully imported", "Confirmation message");
//=================================================END MAIN FUNCTION=================
var pageChecker = (function () {
var myDoc=app.activeDocument;
mylength = myDoc.pages.length,
err=0,
mydiv = ( mylength % 4 ),
myadd = ( 4 - mydiv );
if ( mydiv == 0 ) {
alert( "No issue with Page count. Press OK to go next step." )
};
if ( myadd != 4 ) {
var myconfirmation=confirm ( "Need to add " + myadd + " pages. Shall I add them?" );
if ( myconfirmation ) {
if ( mydiv !=0 ) {
for ( i = 0; i < myadd; i++ ) {
myDoc.pages.add( LocationOptions.BEFORE, myDoc.spreads[-1] );
}
}
}
}
}());
//======================insert an empty page to make the document pages a multiple of 4 (for booklets)
var bm = (function () {
var newDoc = app.activeDocument;
var frame = newDoc.textFrames.everyItem().getElements();
var f = frame.length;
for ( var c = 0; c < f; c++ ) {
var paras = frame
for ( p = 0; p < paras.length; p++ ) {
var langArray = [ "EN", "FR", "DE", "IT", "ES", "NO", "RU", "TR" ];
for ( var i = 0; i < langArray.length; i++ ) {
if ( paras
.contents === langArray ) {
var a = app.activeDocument.hyperlinkTextDestinations.add( paras
);
var bm = app.activeDocument.bookmarks.add( a );
bm.name = paras
.contents;
}
}
}
}
}());
};