Add paragraph style only to a paragraph with 2 lines or more.
Learn / Forums / General InDesign Topics / Add paragraph style only to a paragraph with 2 lines or more.
Tagged: paragraph style 2 lines
- This topic has 17 replies, 6 voices, and was last updated 6 years, 2 months ago by Vinny –.
-
AuthorPosts
-
-
January 13, 2018 at 5:17 pm #100939Year 1917Member
hi
is it possible to make 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 14, 2018 at 12:40 am #100940Claudio MarconatoMember
You can apply a character style to the first 2 lines and then change the character style using nested style by lines, inside the paragraph style options.
-
January 15, 2018 at 5:06 pm #100989Year 1917Member
so i have to do all two line paragraphs manually?
-
January 15, 2018 at 5:39 pm #100991Aaron TroiaParticipant
I don’t think InDesign get’s that specific with their nested styles. I also don’t think there’s a native way to tell InDesign “Apply this style only if the paragraph has greater than or equal to 2 lines.” So yes you will probably have to do them manually, or you might have to look into having someone write a script for something like that.
-
January 15, 2018 at 5:42 pm #100992Year 1917Member
is there someone who knows how to write such a kind of script?
thanks
-
January 15, 2018 at 6:30 pm #100994Aaron TroiaParticipant
I don’t personally know anyone, but I would ask in the InDesign Add-ons (Scripts, Scripting, and Plug-ins) section of the forum.
-
January 16, 2018 at 4:04 am #100998Vinny –Member
This forum is a goldmine to get exercises for scripting ^^
Try this script and tell me if it works for you:
Please note:
– select a text frame, or place the cursor in order to apply the script to the whole story
– an existing character style called “bold” must exist. You can change the name on line 37 (var myCSName = “bold”;)
– script will clear all paragraphs overrides in the selected story, so be cautious
– if you don’t use the download link below and copy/paste your code, please replace opening/closing quotation marks by straight one.
here’s the download link: https://wetransfer.com/downloads/2887b2f63a8f8b3b0fd0adad10e99e7f20180116105700/19df9614bd16a55c5faf1d7bcc0eef8120180116105700/e08e08and here’s the javascript:
//Written by Vinny
// Feel free to modify and usemain();
function main() {
//Make certain that user interaction (display of dialogs, etc.) is turned on.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
if (app.documents.length != 0) {
if (app.selection.length == 1) {
switch (app.selection[0].constructor.name) {
case “Text”:
case “TextFrame”:
case “InsertionPoint”:
case “Character”:
case “Word”:
case “Line”:
case “TextStyleRange”:
case “Paragraph”:
case “TextColumn”:
CheckifCharStyleExists();
break;
default:
alert(“The selected object is not a text object. Select some text and try again.”);
break;
}
} else {
alert(“Please select some text and try again.”);
}
} else {
alert(“No documents are open. Please open a document, select some text, and try again.”);
}function CheckifCharStyleExists() {
var myDocument = app.documents.item(0);
var myParagraphs = app.selection[0].parentStory.paragraphs;
var myCSName = “bold”;
var myCharacterStyle = myDocument.characterStyles.item(myCSName);if (myDocument.characterStyles.item(myCSName) == null) {
alert(“\””+myCSName+”\” character style does not exist. Please create it.”);
} else {
AddNestedStyle();
}function AddNestedStyle() {
app.selection[0].parentStory.clearOverrides(OverrideType.PARAGRAPH_ONLY);for (i = 0; i < myParagraphs.length; i++) {
if (myParagraphs[i].lines.length > 1) {
var myNestedStyle = myParagraphs[i].nestedStyles.add({
appliedCharacterStyle: myCharacterStyle,
delimiter: NestedStyleDelimiters.ANY_WORD,
inclusive: true,
repetition: 2
});
}
}
}
}
} -
January 16, 2018 at 4:10 am #100999Michel Allio for FRIdNGEParticipant
Hi,
Even if it’s not the way I’ld choose, it could of course be done natively into InDesign!
I let the curious guys search a little! …
(^/)
-
January 16, 2018 at 4:13 am #101000Michel Allio for FRIdNGEParticipant
Salut Vincent,
2 lignes de code suffiraient, mais apparemment tu as choisi la version longue [non testée] !
(^/)
-
January 16, 2018 at 4:24 am #101001Vinny –Member
Salut Michel et… bonne année ! ^^
Je te crois sur parole, mais je suis en plein apprentissage du scripting alors j’ai sûrement tendance à être très verbeux. N’hésite pas à partager tes deux lignes, ainsi après avoir été mon Maître es GREP, tu pourras aussi devenir mon Maître es Script ^^
Quant à la possibilité de faire ça nativement, j’avoue je sèche. Utiliser Grep pour compter le nombre de caractères avant que ça “coupe” m’est bien venu à l’esprit, mais c’est évidemment très peu précis et donc à exclure. Un indice ? -
January 16, 2018 at 4:48 am #101002Michel Allio for FRIdNGEParticipant
Bonne Année à toi aussi (ainsi qu’à tous ceux qui ne me l’ont pas encore souhaitée … et ils sont pléthore !) !
Pour ce qui est des 2 lignes de code, elles sont depuis 2 heures sur l’autre section de ce forum [l’auteur a suivi les conseils d’Aaron] !
Pour ce qui est de la solution native, InDesign n’est peut-être pas très fort en calcul et c’est vrai qu’il a du mal à compter les lignes, mais il peut le faire ! … avec les “Styles de lignes imbriqués”. Après, c’est un jeu d’enfant avec un F/R Grep dont voici le code : .$
(^/)
-
January 16, 2018 at 5:14 am #101003Michel Allio for FRIdNGEParticipant
Ce code Grep est … plus intéressant : .$\r?
[Grep est rempli de paradoxes !]
(^/)
-
January 16, 2018 at 9:13 am #101017Masood AhmadParticipant
English please………
This post is a duplicate entry here on InDesign Secrets. Obi-wan have already given a code to achieve this:
Add paragraph style only to a paragraph with 2 lines or more.
-
January 16, 2018 at 12:31 pm #101025Year 1917Member
Thanks for the script
But I have a few comments:
1) The script does each paragraph as a separate action so I can’t do a CTRL Z, can you adjust the script that it adds the style as 1 action.
2) It does not add a character style it just adds the effect (I can’t highlight it and change it to a different style after using the script, nothing will happen)
3) It applies the effect to all paragraphs, can you adjust so it asks on which paragraph style you want to add the effect.
4) It makes an override on the paragraph style.
5) Is it possible to create this effect via the nested styles in the paragraph style dialog.
Also is it possible in GREP format (I want to place a anchored object via GREP before the second word of all paragraphs with 2 lines or more and add a bold effect to the first word (this is necessary for Hebrew typesetting to create drop words))
-
January 16, 2018 at 12:32 pm #101026Year 1917Member
i mean Vinny 38 script
-
January 16, 2018 at 2:46 pm #101033Vinny –Member
Year1917…
When “a few comments” happen to be a list of very specific requests, I guess it’s time to think about hiring a professional scripter.
You can ask obiwan, I’m sure he’ll be glad to help.
All the best -
January 16, 2018 at 6:16 pm #101037Year 1917Member
what do you mean vinny 38 by:
if you don’t use the download link below and copy/paste your code, please replace opening/closing quotation marks by straight one.
can you explain better please?
-
January 17, 2018 at 6:52 am #101043Vinny –Member
I meant that this forum transforms quotation marks like these:”” into curved one (not sure what the right English word is). This causes errors while it comes to JavaScript.
This is probably why you can’t get Obi-Wan script to work properly. Edit the code and replace them.
-
-
AuthorPosts
- You must be logged in to reply to this topic.