Thread View: adobe.scripting.indesign
2 messages
2 total messages
Started by matt_p_stone
Wed, 28 Jan 2009 16:36
Loop through all open documents not performing some actions
Author: matt_p_stone
Date: Wed, 28 Jan 2009 16:36
Date: Wed, 28 Jan 2009 16:36
21 lines
2133 bytes
2133 bytes
I have a loop that imports XML, then Exports each page individually, then has a SaveAs dialog for the indd, then closes the active document.
The import XML works, the SaveAs works, and the close works but the loop skips over the PDF part. Is it because I need to define myCounter in the for loop within the ExportPDF function? I just included the part from Choose XML to the end of ExportPDF.
//choose XML
var FilterXML = "XML File: *.xml";
var myXML = File.openDialog("Choose XML File", FilterXML);
//loop for each action below
for(myDocumentCounter = app.documents.length; myDocumentCounter > 0; myDocumentCounter--){
//import XML
app.activeDocument.importXML(myXML);
//PDF by page to settings; preset must be "dailies_x1a"
function myExportPages(myFolder){
var myPageName, myFilePath, myFile;
var myDocument = app.activeDocument;
var myDocumentName = myDocument.name;
var myBaseName = myBaseNameField.editContents;
for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){ myPageName = myDocument.pages.item(myCounter).name; app.pdfExportPreferences.pageRange = myPageName; //The name of the exported files will be the base name + the page name + ".pdf". //If the page name contains a colon (as it will if the document contains sections), then remove the colon. var myRegExp = new RegExp(":","gi"); myPageName = myPageName.replace(myRegExp, "_"); myFilePath = myFolder + "/" + myBaseName + "_" + myPageName + ".pdf"; myFile = new File(myFilePath); myDocument.exportFile(ExportFormat.pdfType, myFile, false, "dailies_x1a"); } }
Re: Loop through all open documents not performing some actions
Author: matt_p_stone
Date: Wed, 28 Jan 2009 19:03
Date: Wed, 28 Jan 2009 19:03
29 lines
2281 bytes
2281 bytes
Nevermind, I found my error. Code should read...
for(myDocumentCounter = app.documents.length; myDocumentCounter > 0; myDocumentCounter--){
if(app.documents.length != 0){
var myFolder = Folder.selectDialog ("Choose a Folder to Save the PDFs");
if(myFolder != null){
myExportPages(myFolder);
}
}
else{
alert("Please open a document and try again.");
}
function myExportPages(myFolder){
var myPageName, myFilePath, myFile;
var myDocument = app.activeDocument;
var myDocumentName = myDocument.name;
var myDialog = app.dialogs.add();
with(myDialog.dialogColumns.add().dialogRows.add()){
staticTexts.add({staticLabel:"Please Modify the Base Name if Necissary:"});
var myBaseNameField = textEditboxes.add({editContents:myDocumentName,
minWidth:160});
}
var myResult = myDialog.show({name:"ExportPages"});
if(myResult == true){
var myBaseName = myBaseNameField.editContents;
//Remove the dialog box from memory.
myDialog.destroy();
for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){ myPageName = myDocument.pages.item(myCounter).name; app.pdfExportPreferences.pageRange = myPageName; //The name of the exported files will be the base name + the //page name + ".pdf". //If the page name contains a colon (as it will if the //document contains sections), //then remove the colon. var myRegExp = new RegExp(":","gi"); myPageName = myPageName.replace(myRegExp, "_"); myFilePath = myFolder + "/" + myBaseName + "_" + myPageName + ".pdf"; myFile = new File(myFilePath); myDocument.exportFile(ExportFormat.pdfType, myFile, false, "dailies_x1a"); } } else{ myDialog.destroy(); } }
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads