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

[AS][CS3] counting paragraph lines

New Here ,
Sep 20, 2009 Sep 20, 2009

Hi!

Is there a way to count how many lines of text there are on a paragraph and then add some line breaks if there are not enough lines?

jukka

TOPICS
Scripting
2.7K
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

Advocate , Sep 20, 2009 Sep 20, 2009

"count of lines" will give you the number of lines. To add extra lines, just set the contents of the chosen insertion points to newline.

--

Shane Stanley <sstanley@myriad-com.com.au>

AppleScript Pro, April 2010, Florida <http://www.applescriptpro.com>

Translate
Advocate ,
Sep 20, 2009 Sep 20, 2009

"count of lines" will give you the number of lines. To add extra lines, just set the contents of the chosen insertion points to newline.

--

Shane Stanley <sstanley@myriad-com.com.au>

AppleScript Pro, April 2010, Florida <http://www.applescriptpro.com>

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
New Here ,
Sep 21, 2009 Sep 21, 2009

Thanks Shane!

It was right under my nose, i must be blind!

jukka

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
New Here ,
Sep 21, 2009 Sep 21, 2009

Another problem.

I found all the paragraphs that i need, i get the number of lines and if the count of lines is not enough i'll insert returns to the end of paragraph with this loop:

repeat with j from 1 to (11 - theNum)
        set contents of insertion point -1 of theParagraph to return           
end repeat


This works great with first found paragraph but following paragraphs insertion point -1 is not at the end of paragraph.

Baffled...

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 ,
Sep 21, 2009 Sep 21, 2009

Try going backwards through the array

repeat with j from (11-theNum) to 1 by -1

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
New Here ,
Sep 21, 2009 Sep 21, 2009

Thanks Larry but no help.

The insert point is still off after first occurence.

jukka

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
Advocate ,
Sep 21, 2009 Sep 21, 2009

Work backwards, as Larry said, and try insertion point -2 (ie, before the existing return).

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
New Here ,
Sep 22, 2009 Sep 22, 2009

Backwards didn´t help

The amount of drifting from -1 is some how related how many returns are added in the previous turn. If the j loop adds 3 returns then the next (i loop, kappale (i)) paragaphs -1 is 3 chars wrong...

Here some code

--befofre this code gets all stylenames -> theStyle

set theJuttu to object reference of selection
    tell active document
       
        if theStyle is not "false" then
            set theKappaleet to find text of theJuttu
           
            repeat with i from 1 to count of theKappaleet
                set kappale to item i of theKappaleet
                set theNum to count of every line in kappale
                if theNum < 12 then
                    repeat with j from 1 to (11 - theNum)
                       set contents of insertion point -1 of kappale to return & return & return & return
                    end repeat
                end if

             end repeat
        end if
    end tell

I´m not an expert on applescripting indesign so if you have better way doing this then i'm all ears...

Just lookin for a help so i dont have to do this by hand for a 14000+ items.

jukka

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
New Here ,
Sep 22, 2009 Sep 22, 2009

Sorry, the j loop was a test.

Here's right one

repeat with j from 1 to (11 - theNum)
      set contents of insertion point -1 of kappale to return

end repeat

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
New Here ,
Sep 22, 2009 Sep 22, 2009

Also, for what it´s worth:

The paragraph that i'm trying to manipulate has an picture frame as first character and the paragraph also has an Drop cap.

----------  tex text tex text tex text

|           | tex text tex text tex text

|           | tex text tex.

|           |

----------

As in this example this paragraph is 2 lines short of what is needed

jukka

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
Advocate ,
Sep 22, 2009 Sep 22, 2009

> Backwards didn´t help

It will if you actually do it:

             repeat with i from (count of theKappaleet) to 1 by -1

--

Shane Stanley <sstanley@myriad-com.com.au>

AppleScript Pro, April 2010, Florida <http://www.applescriptpro.com>

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
New Here ,
Sep 22, 2009 Sep 22, 2009

Holly smoke, it works!

I was a bit dazed and confused with the i-loop and j-loop but now i got it working.

Thank you Shane and Larry for sorting this for me. Just did it and it took 11 minutes to do it's magic, by hand it would took me fo 1,5 woking days!

The best part is  that i can use it again with my future projects.

Is there any explanation why the loop works backwards?


Do you have any book suggestions for scripting indesign? I have Shirley W. Hopkins book for CS but it's a bit outdated...

Thanks again!

jukka

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
New Here ,
Sep 22, 2009 Sep 22, 2009

Hmm... sometimes

      set theNum to count of every line in kappale

returns wrong number of lines.

Got to get into that later.

jukka

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 ,
Sep 22, 2009 Sep 22, 2009

If you go forward through an array it can mess up the index numbers of the contents. By working backwards, the index numbers are not changed. As to the wrong number of lines, it may be that there is an extra return in the original text.

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
New Here ,
Sep 22, 2009 Sep 22, 2009
LATEST

Ok, got it.

But if theres an extra return, wouldn´t that count as a paragraph?

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