Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

First line of each text frame

Explorer ,
Oct 31, 2023 Oct 31, 2023

Is there a way to specify the number of words or characters in the first line of each text frame that has a given Object style applied?

 

I want to limit the first line to about 3-5 words, for each text frame that has a specific object style applied to it, then every subsequent line to have text as per normal.

TOPICS
How to
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 05, 2023 Nov 05, 2023

Hi @Theo331728749dq2 , A scripting solution might be this—expects a text frame with the applied object style to be selected:

 

 

 

var min = 3
var max = 5
//a selected text frame
var s = app.activeDocument.selection[0];
//random number for forced line break
var rn = Math.floor(Math.random() * (max - min + 1) ) + min;

if (s.constructor.name == "TextFrame") {
    //the selected frame’s object style
    var os = s.appliedObjectStyle;
    var api = app.activeDocument.allPageItems;
    var tf, ii;
 
...
Translate
Community Expert ,
Nov 01, 2023 Nov 01, 2023

One way that might work is to have a GREP or Nested Style built into the Paragraph Style, then have the Object Style trigger the Paragraph style.

So your Paragraph style would have to be Body First Style and then Apply Next Style = Body (all can be triggered in the Object Style)

 

Then in the GREP style for the Body First Style

In the GREP define the amount of words you want - 3 or 5, I can't think of a way to randomise.

And then add no breaks to spaces after these 

 

Maybe a Nested Style would work better?

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 03, 2023 Nov 03, 2023

I havn't been able to get it to work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 03, 2023 Nov 03, 2023

Can  you give an example of the document you're working on and before and after.
You can attach indesign files to your post.

 

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

Object Styles can have Paragraph Styles included. That works only, if the frames are not linked. 

In would rather use a Paragraph Style in linked stories which has in its Keep Options paragraph starts in a new frame and format it with a Line Style in Nested Styles. It you limit the number of words in the first line, you might insert a line break manually. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

That's true it won't work across linked text frames - something I had forgotten.

 

I think we're all agreed some sort of GREP style or Nested style (paragraph or Line) would work. 

 

Just need to see an example to find a way. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

I think the problem here isn't so much defining an object style, but how to create a paragraph style that limits the characters or words on the first line of a multi-line paragraph. Since I don't think that is possible where you want to indent the trailing edge of the first line trying to do this with a paragraph style tied to an object style is moot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

How would line styles (or nested or GREP styles) help here? You can't define the length of the line using thos methods, nor can you use a style to insert a line break.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

I could imagine, a style for the first line, after s specific number of words or glyphs starts a character style which forces a number of glyphs high enough to no-break to force them to the new line.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

OK. Pretty ugly kludge, though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2023 Nov 15, 2023

I've read through this thread a couple of times and can't see where a Nested Style, applied to n words, would not serve. What am I missing?

 

ETA: or a Line Style, with, as noted, author input as to the first line break.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2023 Nov 15, 2023

@James Gifford—NitroPress

 

The assumption is - it can be any ParaStyle applied to the first paragraph of the TextFrame.

 

It might be always the same ParaStyle - document is an end result of the DataMerge so single TF Stories  - or for some strange reason, OP wants this to happen to any TF, even a threaded Story.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2023 Nov 15, 2023

This strikes me as a wetware-driven process, using ID's helper tools, not an automated one. But okay.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2023 Nov 15, 2023

Nested Style, applied to n words, would not serve. What am I missing?

 

I think it's the random line break between 3 & 5 words that can't be handled with a nested style

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2023 Nov 15, 2023

Then a Nested Line Style, which doesn't care how long the line is or any other detail. It's just up to the author/designer to make sure the line breaks in the right place, which is (IMVHO) beyond any kind of automation short of AI.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 03, 2023 Nov 03, 2023

What is the alignment of the text?

For right aligned text you could simply use a large first line indent, but for left aligned the only thing that springs to mind is to use two threaded text frames, the first only one line high, and add a hefty right indent to that one-line frame.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

But then you would need a script to calculate right indent for each case / 1st TF ? 

 

Because OP wants 3-5 words... 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2023 Nov 05, 2023

OP hasn't set a hard limit. My sense is that they want up to a certain number of characters on the line and that should accomodate three to five "average" length words.

I regard this as basically adding a right indent to the first line (for left aligned text). The right margin would remain either justified or ragged according to the paragraph specs. In justified text the the first line would always be the same length, adjusting the spacing, in ragged text the first line might be shorter on some paragraphs, just as other lines in the paragraph can be short of the margin.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

I have reconsidered all. Instead of making a line style a separate paragraph with its own paragraph style would be much better. So you can avoid problems with justified text and odd word spacing. Where to separate the first paragraph from the rest is a task of the author. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

I guess you can set a nested style or GREP style that makes the 6th word too large to fit in the frame causing an overset. You would have two paragraph styles theobject style setting to "first" and Next style of "first" should be "following" (and followingdoes not have that GREP or Nested style)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

Using two frames as I suggested earlier requires only a single paragraph style and no manual manipulation to force a break. The first frame will accept text up to the point where the right inset is met and the remaining text will move to the next frame automatically.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2023 Nov 05, 2023

Hi @Theo331728749dq2 , A scripting solution might be this—expects a text frame with the applied object style to be selected:

 

 

 

var min = 3
var max = 5
//a selected text frame
var s = app.activeDocument.selection[0];
//random number for forced line break
var rn = Math.floor(Math.random() * (max - min + 1) ) + min;

if (s.constructor.name == "TextFrame") {
    //the selected frame’s object style
    var os = s.appliedObjectStyle;
    var api = app.activeDocument.allPageItems;
    var tf, ii;
    for (var i = 0; i < api.length; i++){
        //get all text frames with the same style
        if (api[i].constructor.name == "TextFrame" && api[i].appliedObjectStyle == os){
            tf = api[i];
            //clear any existing force line breaks
            if (tf.lines[0].characters[-1].contents == SpecialCharacters.FORCED_LINE_BREAK) {
                tf.lines[0].characters[-1].contents = ""
            }
            //insert line break
            var ip = tf.lines[0].words[rn].insertionPoints[0]
            ip.contents = SpecialCharacters.FORCED_LINE_BREAK;
        }
    };   
} 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2023 Nov 05, 2023

Great script - as always. 

 

But I can bet, that OP want this to work only when paragraph starts in the TextFrame? Not middle lines? 

 

So extra check if Paragraph starts in TextFrame would be needed? 

 

Unless those are unthreaded TextFrames - effect of DataMerge? 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2023 Nov 05, 2023

Another question is whether @Theo331728749dq2  really wants a random break or is it the " best" break given a short measure?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2023 Nov 05, 2023

I like the scripting solution, but of course it isn't automatic and would need to be revisited when there is a text edit that could affect the first line.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines