Add paragraph style only to a paragraph with 2 lines or more.

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Add paragraph style only to a paragraph with 2 lines or more.

Viewing 11 reply threads
  • Author
    Posts
    • #100995
      Year 1917
      Member

      hi

      is there a script to add a paragraph style only to paragraphs with 2 lines or more?

      (example: i want the first word of paragraphs with 2 lines or more to have a certain effect (bold etc.))

      thanks

    • #100996

      Hi,

      Imho, surely not!

      … But if you ask:

      Is there somebody who could write such a script?

      … the answer could be “Yes!”

      (^/)

    • #100997

      … And as it’s too simple, it will be for free this time! …

      var myParas = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements(), P = myParas.length, p;
      for ( var p = 0; p < P; p++ ) if ( myParas[p].lines.length > 1 ) myParas[p].appliedParagraphStyle = “Red”;

      [… supposing you want to apply a “Red” para style that includes such a grep style: ^\w+ [bold char style]!]

      (^/)

    • #101007
      Masood Ahmad
      Participant

      I might be wrong, but I think ^\w+ means first word only. For two words the code could be something like this: ^\w+\s\w+.

      …… OR ……

      It will be much easier to use Nested Styles to apply the Bold character style to the first two words.

    • #101024
      Year 1917
      Member

      Thanks

      I tried to use the script it gives back an error, can you explain how to use.

      JavaScript error!
      Error string: syntax error

      Engine: main
      File: (location)

      Line:5
      Source: =”red”;
      Offending text: ”

      Thanks

    • #101029

      “Red” is the name of the para style you want to apply!!!!

      Maybe [surely] you para style has another name!

      (^/)

    • #101030
      Year 1917
      Member

      no thats not the problem i tried to create a para style with the name red.

      also does it apply to all text in the document

    • #101031

      1/ The name is not “red” but “Red”!
      2/ The script searches in all the paras the paras with 2 lines or more and apply to them the “Red” para style.

      … So, if you include in “Red” para style a grep style [^\w+] with “Bold” char style associated, ALL THE PARAS WITH MORE THAN 1 LINE WILL HAVE THE “RED” PARA STYLE, AND SO, THE FIRST WORD OF THE PARA IN “BOLD”!

      (^/)

    • #101032

      You’re wrong Masood! Read the original post.

      (^/)

      [ For 2 words, use this: ^(\w+)\h(?1) ]

      • #101045
        Masood Ahmad
        Participant

        I think it’s time to replace my specs :)

    • #101036
      Year 1917
      Member

      Obi-wan Kenobi, the script does not work can you try for yourself and see.

    • #101040

      I’ve obviously tested it before posting it!

      (^/)

    • #101042
      Year 1917
      Member

      please start explaining how to use from beginning

      does it work for cc2018?

Viewing 11 reply threads
  • You must be logged in to reply to this topic.
>