Copy link to clipboard
Copied
I am working on a book of poems. I need to make sure that the (left aligned) text running within each page is centred on the longest line. As far as I am aware there is no mechanism for doing this automatically in inDesign and besides, the optical centre will always be different from the actual centre.
So I need to manually add an indent to every page to indent the text until it feels centred on the page. My problem is that some of the stanzas/paragraphs run between two pages which each need different indentation. I can only apply indent to a whole paragraph, meaning it will effect the beginning of the paragraph on one page and the end on another. If the second page requires a different indent this means the end of the paragraph that has run over from the previous page will indented correctly for the previous page and not the current page or vice-versa.
Is there any sensible solution to this problem?
I've had some good fun setting poetry in the past. Most of it can be scripted. As Ariel and Bill mentioned, each line should be a separate paragraph. Then you can left-align the lines and centre the page on the longest line using the following script:
Select a text frame, then run the script
...if (app.selection.length && app.selection[0] instanceof TextFrame) {
frame = app.selection[0];
longest = Math.max.apply (null, frame.lines.everyItem().endHorizontalOffset);
indent = (frame.geometricBounds[3
Copy link to clipboard
Copied
I can't figure out how to delete this double comment—sorry, folks!
Copy link to clipboard
Copied
Hi there! I'm trying to use this script for a memoir I'm typesetting (with mixed content—some normal paragraph styles, with poems intersperced throughout).
I changed the paragraph style to my own, but when I try to run the script, I'm getting a JavaScript Error:
It seems like something in line 9 is causing the issue and it's probably a simple fix... but this is the ceiling of my JavaScript knowledge. Please help—thank you SO much!
Thanks! Pasting full code below:
/*
0190_PoetryLines_MichelAllio.jsx
based on an orginal code written by Peter Kahrel | See: https://forums.adobe.com/thread/2370094
Written 2017/08/13
*/
app.doScript(main, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Poetry Lines! …" );
function main()
{
var myDoc = app.activeDocument,
myPages = myDoc.pages,
P = myPages.length, p;
for ( p = 0; p < P; p++ )
{
var myFrames = myPages[p].allPageItems,
F = myFrames.length, f;
for ( f = 0; f < F; f++ ) {
var myFrame = myFrames[f];
if ( myFrame instanceof TextFrame && myFrame.contents.length > 0 )
{
var longest = Math.max.apply (null, myFrame.lines.everyItem().endHorizontalOffset);
var indent = (myFrame.geometricBounds[3]/2) - (longest/2);
myFrame.lines.everyItem().leftIndent = indent;
}
}
}
var myParas = myDoc.stories.everyItem().paragraphs.everyItem().getElements();
var P = myParas.length, p;
for ( p = 0; p < P; p++ ) myParas[p].appliedParagraphStyle != myDoc.paragraphStyles.item("Poem Body–A (Ljust) START") && myParas[p].clearOverrides();
};
Copy link to clipboard
Copied
FWIW: I marked Peter Kahrel's post from Aug 13, 2017 as the Correct one.
Why? It contains the core code for solving this issue.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Dear gurus! I never would have thought that I would be writing in the same thread as the legendary Peter )))
I am having trouble with Uwe Laubender's script (also quite legendary). It worked perfectly until recently, and I was able to create a collection of poems quite quickly, thanks to you all. However, now, unfortunately, something has broken in it. It functions properly with a small number of poems or pages, but as soon as I add a significantly larger batch of poems, it tries to center them, then reverts the lines back to their original place and gives an error: Data is out of range (line 301).
Unfortunately, I don't understand anything about scripting, and I am asking for your help.
Thank you, and I apologize for the English; it's Google.
Copy link to clipboard
Copied
Hi @popz29907986ftco ,
hm, is it perhaps the script code commented with this line:
0190_PoetryLines_MichelAllio.jsx
This code was not wriiten by me, it is @Obi-wan Kenobi 's one.
Without having a sample InDesign document at hand it's hard to tell what's going wrong.
Also important is the version of your InDesign.
Could you attach a sample document and give the URL of the post where the script code is posted?
NOTE: Attaching an InDesign document will only work if you are using the forum's editor and not when you answer by mail.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
I work in the 17.4 Indesigne, running Windows 10. In the archive, work and script itself. I took the script from this thread about a year ago and it invariably helped me. What could go wrong? Thank you for responding and trying to help.
Copy link to clipboard
Copied
Hi @popz29907986ftco ,
if you refer to the script file CenterLines.js that you provided with your packaged InDesign document, well, that's not the code @Obi-wan Kenobi provided in this thread.
Also: I see a lot of overset text in your document.
That could be the cause of failure of your script.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Oops. Absolutely true. Now I have compared the codes of two scripts and they are completely different. I'm sorry. Apparently I took this script in another place. Fine. Forget about him.
I have now copied Peter's code, inserted it into the NOTEPAD++ program and saved it as Pitercenter.js
Launched the entire text, no oversets, selected a text frame and launched PiterCenter.js
Unfortunately, I got an error. I would be very grateful for clarification.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Find more inspiration, events, and resources on the new Adobe Community
Explore Now