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

how to skip enter lines(empty lines) count between no of lines selection in indesign

Engaged ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

var myText = app.selection[0].lines;
var b;
var c=0;
for (i=0; i<myText.length; i++){     
  if(myText[i].characters[0].contents ==0){
      c =i-1;
      break;
      }                      
  if (c != 0){
      b=i-1;
      }
  else{
          b=i+1;
      }
  if(b % 5 === 0){
   var myInsertion= myText[i].insertionPoints[0];
   var mycontent = myText[i].contents
    }
}

is there any way to count length of lines by skipping empty lines in indesign??

Screenshot 2022-02-15 105744.png

TOPICS
How to , Scripting

Views

1.2K

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 4 Correct answers

Community Expert , Feb 23, 2022 Feb 23, 2022

Try this

 

var p = app.selection[0].paragraphs;
var cnt = 0

for (i=0; i<p.length; i++){     
    if (checkParagraph(p[i]) == 0) {
        //the paragraph has text insert cnt at beginning
        cnt++
        p[i].insertionPoints[0].contents = cnt + ". ";
    } 
}


/**
* Check for empty paragraphs 
* @Param paragraph to check 
* @Return grep array length, 1 if the paragraph is empty
* 
*/
function checkParagraph(p){
    app.findGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences
...

Votes

Translate

Translate
Community Expert , Feb 23, 2022 Feb 23, 2022

Or are you looking for this, which would require soft returns and no hyphenation:

 

Screen Shot 27.png

Votes

Translate

Translate
Engaged , Feb 23, 2022 Feb 23, 2022

Now this works for me

var p = app.selection[0].lines;
var cnt = 0
for (i=0; i<p.length-1; i++){     
    if (checkLine(p[i]) == 0) {
        cnt++;
        p[i].insertionPoints[0].contents = cnt + ". ";
    } 
}
function checkLine(p){
    app.findGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = "^\\s*\r";
    var a = p.findGrep();
    app.findGrepPreferences = NothingEnum.nothing;
    return a.length;
}

Votes

Translate

Translate
Community Expert , Feb 24, 2022 Feb 24, 2022

Hi @Karthik SG , for that to work your "lines" must be single line paragraphs? This is what I get when the paragraphs have more than one line, which is what your original post was showing:

 

Screen Shot 28.pngScreen Shot 29.png

 

 

This version works by inserting a forced line break at the end of the line above, but you would have a mess if you need to edit after running the script:

 

 

 

var p = app.selection[0].paragraphs;
var lns;
var cnt = 0

for (i=0; i<p.length; i++){     
    if (checkParagraph(p[i])==0) {
        p[i].hyph
...

Votes

Translate

Translate
Community Expert ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

Do you want to count the number of non empty lines in the selection? If so try the following

app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "^\r";
var a = app.selection[0].findGrep();
alert(app.selection[0].lines.length - a.length)
app.findGrepPreferences = NothingEnum.nothing;

-Manan

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
Engaged ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

trying to change line number after empty line to empty line number..

empty line number: 13

next line number: 14 (now new line number should be 13 and get this line content)

 

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 ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

I lost it, did not understand your latest comment completely. What do you want to do? Lets start from basic.

  • Did the script I gave, give you the number of lines correctly in your selection or not by avoiding the blank lines?
  • If the answer above is yes then do you want to further process that data? If so how and what does not seem to work in that case. A visual example would be nice to understand
  • If the above points are not relevant and you wanted to do something else then start afresh and expalin it better on what you intend to do

-Manan

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 ,
Feb 19, 2022 Feb 19, 2022

Copy link to clipboard

Copied

Our Karthik is a bit confused. His first question was: how to get the line count of non-empty lines. Now he wants to number the lines but not blank ones.

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
Engaged ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

Sorry, It's due to lack of communication. I failed to explain my question correctly! Thanks for the response. I will correct myself😅

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
Engaged ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

Hey Manan sorry for the confusion, I am actually trying to insert line number for each line of multiple selected paragraph lines. In between each paragraph I have an enter mark(empty) line which also getting line number inserted. Now I need to skip that line from numbering. 

 

  1. For example: Consider a paragraph has 5 lines and next paragraph has 4 lines. Now I am having empty line between two paragraphs. When I start to insert line number for each line I am getting 10 line counts but actually I have only 9 lines with content. Here my question comes! How to skip that empty line(line no:6) without numbering and continue line numbering from 2nd paragaph 1st line as(line no:6) ? 

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 ,
Feb 19, 2022 Feb 19, 2022

Copy link to clipboard

Copied

Hi Manan, a line could have white space plus the return, so @Karthik SG might need to search for lines with any white space plus the return. So maybe this:

 

app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "^\\s*\r";
var a = app.selection[0].findGrep();
alert("The selected " + app.selection[0].lines.length + " lines contains " + a.length + " empty line")
app.findGrepPreferences = NothingEnum.nothing;

 

 

Screen Shot 11.png

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 ,
Feb 19, 2022 Feb 19, 2022

Copy link to clipboard

Copied

Thanks for making the solution more robust. However, OP seems to have ghosted us so we are as clueless as before as to what is needed afterall 🙂

-Manan

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
Engaged ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

  • Hey Rob, thanks for the response! I am trying to insert line number for already selected n number of lines to each line which has content and empty line should not be inserted with line number.. with your example,
  • This is I am getting so far, 
  • 1.Hello
  • 2.
  • 3.there
  • What I actually want is, 
  •    1. Hello
  •  
  •     2.there

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 ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

Try this

 

var p = app.selection[0].paragraphs;
var cnt = 0

for (i=0; i<p.length; i++){     
    if (checkParagraph(p[i]) == 0) {
        //the paragraph has text insert cnt at beginning
        cnt++
        p[i].insertionPoints[0].contents = cnt + ". ";
    } 
}


/**
* Check for empty paragraphs 
* @Param paragraph to check 
* @Return grep array length, 1 if the paragraph is empty
* 
*/
function checkParagraph(p){
    app.findGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = "^\\s*\r";
    var a = p.findGrep();
    app.findGrepPreferences = NothingEnum.nothing;
    return a.length;
}

 

Screen Shot 26.png

 

Screen Shot 25.png

 

But what‘s the reason for the empty return? Why not remove the returns, and use a Space After and a Numbered List?

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 ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

Or are you looking for this, which would require soft returns and no hyphenation:

 

Screen Shot 27.png

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
Engaged ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

Yes I am looking for this only! 

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 ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

But adding text to existing lines could change the line endings. Like for example adding "1. " would add three characters so the line ending will shift by three characters. What sense it would make then? If we add soft return before adding the characters then also it will cause a mess as the 2 characters and soft return would wrap on to new line I suppose.

-Manan

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
Engaged ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

Now this works for me

var p = app.selection[0].lines;
var cnt = 0
for (i=0; i<p.length-1; i++){     
    if (checkLine(p[i]) == 0) {
        cnt++;
        p[i].insertionPoints[0].contents = cnt + ". ";
    } 
}
function checkLine(p){
    app.findGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = "^\\s*\r";
    var a = p.findGrep();
    app.findGrepPreferences = NothingEnum.nothing;
    return a.length;
}

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 ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

Hi @Karthik SG , for that to work your "lines" must be single line paragraphs? This is what I get when the paragraphs have more than one line, which is what your original post was showing:

 

Screen Shot 28.pngScreen Shot 29.png

 

 

This version works by inserting a forced line break at the end of the line above, but you would have a mess if you need to edit after running the script:

 

 

 

var p = app.selection[0].paragraphs;
var lns;
var cnt = 0

for (i=0; i<p.length; i++){     
    if (checkParagraph(p[i])==0) {
        p[i].hyphenation = false;
        cnt++
        lns = p[i].lines;
        for (var j = 0; j < lns.length-1; j++){
            lns[j].insertionPoints[0].contents = cnt + ". ";
            lns[j].insertionPoints[-1].contents = SpecialCharacters.FORCED_LINE_BREAK;
            cnt++
        }; 
        lns.lastItem().insertionPoints[0].contents = cnt + ". ";
    } 
}


/**
* Check for empty paragraphs 
* @param paragraph to check 
* @return grep array length, 1 if the paragraph is empty
* 
*/
function checkParagraph(p){
    var isEmpty = 1
    try {
        app.findGrepPreferences = NothingEnum.nothing;
        app.findGrepPreferences.findWhat = "^\\s*\r";
        a = p.findGrep();
        isEmpty = a.length
        app.findGrepPreferences = NothingEnum.nothing;
    }catch(e) {}  
    return isEmpty;
}

 

 

 

 

Screen Shot 30.png

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 ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

Maybe place a separate text frame to the left of the frame with the content and place the numbers there.

P.

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
Engaged ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

As you think, I am adding it in separate textFrame. So no issues with that!

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
Engaged ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

LATEST

Yes! I too noticed while trying to insert in starting of each line. For this purpose what you explained is absolutely correct. thanks for your response and time @rob day 

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 ,
Feb 19, 2022 Feb 19, 2022

Copy link to clipboard

Copied

Wouldn't using paragraph spacing instead of extra returns solve the count issue? It's a better InDesign workflow too. 

David Creamer: Community Expert (ACI and ACE 1995-2023)

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Absolutely.

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