-
1. Re: Loop Page Style Sheet to set file name.
Kai Rübsamen Apr 24, 2014 2:04 AM (in response to cathykka)Some questions:
1. Do you have only those 2 paragraph styles?
2. What should happen, if both paragraph styles are on the same page > which style should create the filename?
3. Your mentioned script insert always a "0" in front of the pages name > what should happen, if you have more than 9 pages?
4. What should happen, if there is no found of one of the styles on a page?
Find attached my current version of the script. The script is not perfect at the moment, because the above questions are not clear to me. Nervertheless it should produce a result ;-)
main (); function main() { var curDoc = app.activeDocument; // Array of paragraph Style names var paraStyleNames = ["h1", "h2"]; // insert here your para names ! var missingParaStyles = []; // check, if the styles are valid for ( var p = 0; p < paraStyleNames.length; p++ ) { var curName = paraStyleNames[p]; // if the style is missing, push it to the array if ( !curDoc.paragraphStyles.itemByName(curName).isValid ) { missingParaStyles.push( curName ); } } // if some styles are missing, give an alert var nMiss = missingParaStyles.length; if ( nMiss > 0 ) { var display = missingParaStyles.join( "\r" ); alert ( "Missing para(s):\r" + display ); exit(); } // loop through pages for ( var i = 0; i < curDoc.pages.length; i++ ) { // the current page var curPage = curDoc.pages[i]; // the current page name var pName = curPage.name; var allPageParas = curPage.textFrames.everyItem().paragraphs.everyItem().getElements(); for ( var p = 0; p < allPageParas.length; p++ ) { var curPara = allPageParas[p]; if ( curPara.appliedParagraphStyle.name == paraStyleNames[0] || curPara.appliedParagraphStyle.name == paraStyleNames[1] ) { var paraContents = curPara.contents; var paraString = "-" + paraContents.replace( /\s+$/ , "" ).replace( /\s+/g , "-" ).toLowerCase(); break; } // end if } // end for > allPageParas //~ var folderPath = "~/-client/JOYS - Just Organize Your Stuff/-Art/-art-book-kindle/"; var folderPath = Folder.desktop; var filePath = folderPath + "/" + curDoc.name.replace(/\.indd$/,"") + "-0" + pName + paraString + ".jpg"; var myFile = File( filePath ); with ( app.jpegExportPreferences) { jpegQuality = JPEGOptionsQuality.high; // low medium high maximum exportResolution = 72; jpegExportRange = ExportRangeOrAllPages.exportRange; pageString = pName; } curDoc.exportFile( ExportFormat.jpg, myFile, false ); } // end for > pages } // end main -
2. Re: Loop Page Style Sheet to set file name.
cathykka Apr 24, 2014 4:31 AM (in response to Kai Rübsamen)Thanks Kai.
1. Do you have only those 2 paragraph styles?
no. there are many more. but depending on the file I will use different ones.
2. What should happen, if both paragraph styles are on the same page > which style should create the filename?
both will not be on the same page
3. Your mentioned script insert always a "0" in front of the pages name > what should happen, if you have more than 9 pages?
I would just like a 0 in front of the single page numbers 1-9 so the files are organized by page number
4. What should happen, if there is no found of one of the styles on a page?
Not really important. Null is fine.
Trying you script now. Again... thanks so much.
-
3. Re: Loop Page Style Sheet to set file name.
cathykka Apr 24, 2014 5:10 AM (in response to Kai Rübsamen)Kai. This worked perfectly for my needs. Removing the leading zero before the multidigit page numbers would be awesome... but this is exactly what I needed. Much appreciation to you.
-
4. Re: Loop Page Style Sheet to set file name.
Kai Rübsamen Apr 24, 2014 5:32 AM (in response to cathykka)Good to hear .
Find attached the next version. You can now insert in 'paraStyleNames' as many style names as you want. The script will check from left to right, if there is one found on the page. If this is true, the script will ignore the other styles.
Removing leading zero should work now.
Maybe one problem: If one page contains no style, this page will be exported nevertheless with it’s correct page number, but with the founded text of the previous page. If this can never happen, we are done and you should mark the answer as correct. If this is a real problem for you, please let me know, what should happen in this case and I will try to fix that too.
// Export pages as JPG with additional info by Kai Rübsamen // http://forums.adobe.com/message/6326425#6326425 main (); function main() { var curDoc = app.activeDocument; // Array of paragraph Style names var paraStyleNames = ["h1", "h2"]; // insert here your para names ! var missingParaStyles = []; // check, if the styles are valid for ( var p = 0; p < paraStyleNames.length; p++ ) { var curName = paraStyleNames[p]; // if the style is missing, push it to the array if ( !curDoc.paragraphStyles.itemByName(curName).isValid ) { missingParaStyles.push( curName ); } } // if some styles are missing, give an alert var nMiss = missingParaStyles.length; if ( nMiss > 0 ) { var display = missingParaStyles.join( "\r" ); alert ( "Missing para(s):\r" + display ); exit(); } // loop through all pages for ( var i = 0; i < curDoc.pages.length; i++ ) { // the current page var curPage = curDoc.pages[i]; // the current pages name var pName = curPage.name; // controls the loop var controller = true; // all paragraphs on the current page var allPageParas = curPage.textFrames.everyItem().paragraphs.everyItem().getElements(); // loop through all paragraphs and check, if one has the para style applied for ( var p = 0; p < allPageParas.length; p++ ) { if ( !controller ) break; // the current para var curPara = allPageParas[p]; // loop through the styles for ( var n = 0; n < paraStyleNames.length; n++ ) { if ( curPara.appliedParagraphStyle.name == paraStyleNames[n] ) { var paraContents = curPara.contents; var paraString = "-" + paraContents.replace( /\s+$/ , "" ).replace( /\s+/g , "-" ).toLowerCase(); controller = false; break; } // end if } // end for paraStyleNames } // end for allPageParas //~ var folderPath = "~/-client/JOYS - Just Organize Your Stuff/-Art/-art-book-kindle/"; var folderPath = Folder.desktop; if ( pName < 10 ) { var appendix = "-0" + pName + paraString; } else { var appendix = "-" + pName + paraString; } var filePath = folderPath + "/" + curDoc.name.replace(/\.indd$/,"") + appendix + ".jpg"; var myFile = File( filePath ); with ( app.jpegExportPreferences ) { jpegQuality = JPEGOptionsQuality.high; // low medium high maximum exportResolution = 72; jpegExportRange = ExportRangeOrAllPages.exportRange; pageString = pName; } curDoc.exportFile( ExportFormat.jpg, myFile, false ); } // end for pages } // end main–Kai
-
5. Re: Loop Page Style Sheet to set file name.
cathykka Apr 24, 2014 5:57 AM (in response to Kai Rübsamen)Kai you're a blessing and I am grateful! Worked perfectly.


