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

Counting line in paragraph

Explorer ,
Mar 30, 2017 Mar 30, 2017

Copy link to clipboard

Copied

Hello,

I usually work with structured FM doc, but for once i need to work with unstructured doc.

I need to make a script that check if there is only few chararter at the last line of a paragraph, and if yes, to apply a "spread -2%". and check if i lost one line.

I was thinking, if i can compare the number of line of a paragraph before and after the "spread -2%" and if it's "after" is smaller than "before".

If yes => i lost one line in my paragraph.

In million paragaph, i can win few pages in my doc (doc large than 1.000 pages)

I already have script to walkthrouth all the paragraph of a doc, another to apply and/or check paragraph values (spread).

But how can i count the number of line in one paragraph?

Do i have to put my cursor in each line of my paragraph and check the FTI_LineEnd (normal, hard, hyphen) to know when i reach the end of my paragraph? Or there is another way?

TOPICS
Scripting

Views

873

Translate

Translate

Report

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

Mentor , Mar 31, 2017 Mar 31, 2017

After posting that, I thought of this, which seems to do the same thing:

var ti = pgf.GetText(Constants.FTI_LineEnd);

If it requires less memory and/or processing, that might be better. I don't know if it does or not.

Russ

Votes

Translate

Translate
Mentor ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Hi philippep2776167,

I think the easiest way to count lines in a paragraph is to retrieve the text items, then just look at the length of the array. For example:

var ti = pgf.GetText(Constants.FTI_String);

The length of "ti" will be the number of lines in the paragraph. For example, if the paragraph is 5 lines long, then:

ti.len == 5

Russ

Votes

Translate

Translate

Report

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
Mentor ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

After posting that, I thought of this, which seems to do the same thing:

var ti = pgf.GetText(Constants.FTI_LineEnd);

If it requires less memory and/or processing, that might be better. I don't know if it does or not.

Russ

Votes

Translate

Translate

Report

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
Advocate ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Hi Russ (and Philippe)

The array of strings may in fact have more elements than the number of lines. I cannot give you precise examples for unstructured text, but I did see them. The search for LineEnd is safer.

Ciao

Jang

Votes

Translate

Translate

Report

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 ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Hello Russ (and Rick),

I was thinking that the FTI_LineEnd was giving type of the end of line (see something like than in the FM scripting PDF ... but my english not so good, maybe why I understand wrong).

Thanks alot for the help

Votes

Translate

Translate

Report

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
Advocate ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Hi Russ,

Yes, the LineEnd markers also include the type of the end of line (hard return at the end of a paragraph, soft return when the line is wrapped because there is no more space for the characters). This is because you can also ask for all the LineEnd markers in a section (or in an element in structured FM), not just in a single paragraph.

But when you get the LineEnd markers in a single paragraph (in unstructured FM), you will only have one hard return and possibly a bunch of soft returns. For your script, you only need to know if the total number of LineEnd markers has changed.

Good luck

Jang

Votes

Translate

Translate

Report

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 ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Thanks jang (sorry i put Rick previously, was an error from me )

Votes

Translate

Translate

Report

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 ,
Mar 31, 2017 Mar 31, 2017

Copy link to clipboard

Copied

Just a note about Russ's first reply: the number of FTI_String items can be much more than the number of lines. You get a new FTI_String every time there is a property change in the paragraph or if a string is interrupted by a marker, text frame, table, etc. The FTI_LineEnd count is definitely the way to go.

Votes

Translate

Translate

Report

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
Mentor ,
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

LATEST

Rick and Jang, thanks for straightening me out!

Votes

Translate

Translate

Report

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