Hi Julian, my workflow will only work in CS6 and above. If I tried your script, I had the same problems. Even if I use the loop for all pages instead of allParagraphs. First I think the script must be a bit quicker, if you check not every paragraph (more than 5000), instead I check in my version every page and assume, that the page has one textframe and the first para in this textframe must be my target. The problem for me in this case is 'smartTextReflow'. So I found here in the forum a line 'myDocument.recompse()' and it seems, that this solves the problem. Try this:
app.doScript( allOverAgain, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Run the script!" );
function allOverAgain() {
var myDocument = app.activeDocument;
var myPGS_CS = myDocument.paragraphStyles.item( "Chapter Subheading" );
var allPages = myDocument.pages;
for ( var p = 0; p < allPages.length; p++ ) {
var curPage = allPages ;
var tf = curPage.textFrames[0];
var firstPara = tf.paragraphs[0];
if ( firstPara.appliedParagraphStyle.name != myPGS_CS.name ) {
continue;
}
var chapterSubheading = firstPara;
var chapterHeading = tf.paragraphs[1];
var chapterFirstPara = tf.paragraphs[2];
var myStartFrame = tf;
myStartFrame.geometricBounds = [ 170 , 606 , 1026 , 52 ];
myStartFrame.textFramePreferences.insetSpacing = [ 70 , 45 , 88 , 45 ];
//Then, add the cover image text frame on the current page.
var targetPage = myStartFrame.parentPage;
var myChapterImageTF = targetPage.textFrames.add( {geometricBounds: [ 0 , 663 , 300 , 0 ] , name: "chaptercover" } );
myChapterImageTF.sendToBack();
myDocument.recompose();
}
} // End allOverAgain function
// end of the action
var dlog = new Window( "palette" );
dlog.size = [ 320 , 100 ];
dlog.add( "statictext" , [ 80 , 100 , 320 , 116 ], "Done." );
dlog.show();
$.sleep(1500);
dlog.close();
btw: Do you realize, that you can use margins in your doc and that every frame has a white fill and stroke > no good practice! best –Kai
... View more