sometimes it’s better to loop backwards than forwards. But to find your error, it would be helpful to have your document.
Apart from that, I would solve the task differently:
1. Create two masterspreads with primary text frame enabled (since CS6)
2. The primary text frame on masterspread two sits lower and the masterspread has also the placeholder for the chapter image
3. So search for your paragraph and apply a different masterpage to the corresponding page
thank you so much for your reply. Unfortunately, I'm currently limited to using CS5.5, so I don't suppose your solution would work.
I've tried looping backwards before, but that seemed to alter the text frames on the wrong page. Might be I overlooked something there, though, so if you could give it a go that would be amazing.
Files can be found here:
Thanks so much again, and kind regards,
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.
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!
That's perfect; recompose() was exactly what I was looking for! I do know that the script is far from efficient - in my desperation I've been playing around so much that I'm going to need to do some serious streamlining to get it all somewhat presentable again. ;-)
I do realize fill and stroke on the text frames; later on in the same script the page background will be changing color, so I'd need the text frame to be separately colored to remain its legibility.
In any case, thanks so much for your kind help, you've been an absolute life saver!