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.
Tagged: paragraph style 2 lines
- This topic has 12 replies, 3 voices, and was last updated 6 years, 3 months ago by Masood Ahmad.
-
AuthorPosts
-
-
January 15, 2018 at 8:59 pm #100995Year 1917Member
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
-
January 16, 2018 at 1:04 am #100996Michel Allio for FRIdNGEParticipant
Hi,
Imho, surely not!
… But if you ask:
Is there somebody who could write such a script?
… the answer could be “Yes!”
(^/)
-
January 16, 2018 at 2:36 am #100997Michel Allio for FRIdNGEParticipant
… 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]!]
(^/)
-
January 16, 2018 at 9:03 am #101007Masood AhmadParticipant
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.
-
January 16, 2018 at 12:30 pm #101024Year 1917Member
Thanks
I tried to use the script it gives back an error, can you explain how to use.
JavaScript error!
Error string: syntax errorEngine: main
File: (location)Line:5
Source: =”red”;
Offending text: ”Thanks
-
January 16, 2018 at 12:39 pm #101029Michel Allio for FRIdNGEParticipant
“Red” is the name of the para style you want to apply!!!!
Maybe [surely] you para style has another name!
(^/)
-
January 16, 2018 at 12:43 pm #101030Year 1917Member
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
-
January 16, 2018 at 1:02 pm #101031Michel Allio for FRIdNGEParticipant
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”!
(^/)
-
January 16, 2018 at 1:05 pm #101032Michel Allio for FRIdNGEParticipant
You’re wrong Masood! Read the original post.
(^/)
[ For 2 words, use this: ^(\w+)\h(?1) ]
-
January 17, 2018 at 7:00 am #101045Masood AhmadParticipant
I think it’s time to replace my specs :)
-
-
January 16, 2018 at 5:56 pm #101036Year 1917Member
Obi-wan Kenobi, the script does not work can you try for yourself and see.
-
January 17, 2018 at 1:33 am #101040Michel Allio for FRIdNGEParticipant
I’ve obviously tested it before posting it!
(^/)
-
January 17, 2018 at 6:05 am #101042Year 1917Member
please start explaining how to use from beginning
does it work for cc2018?
-
-
AuthorPosts
- You must be logged in to reply to this topic.