Copy link to clipboard
Copied
Hello Great people
Hope everyone doing good,
I want to create a script for selcting a pragraph style in Indesign and I wanto give a script lable that particular paragaraph style. Can any help on this? Please find the code which is I am using now
app.selection[0].paragraphStyles.item = "heading1";
Please guide me with the correct code.
Thanks in advance
Sandeep.
Hi @Sandeep27041541kg7t , If you check the Script Label panel, you will find that you can’t apply a label to a selected paragraph, which is why you get an error in your script when it selects a paragraph and tries to set a label.
If I select some text, I can’t edit the Script Label field:
But if I select a page item or a text frame, the Script Label field is editable. A paragraph’s parent text frame could have a label set—myParas[i].parentTextFrames[0].label = "TODO"—but not the paragra
...Copy link to clipboard
Copied
If you want to set label on paragraphstyle then you can use the following code
var ps = app.documents[0].paragraphStyles.itemByName("Name of your style")
ps.insertLabel("key", "value")
P.S.:- This will not work with styles inside groups.
-Manan
Copy link to clipboard
Copied
Thanks Manan your quick response but it is not working for me
Paragrah Style Name is : Heading and Lable name is : Sandeep
Please guide me on this.
Copy link to clipboard
Copied
Share the exact code you used and also tell how did you verify that the label was not set.
-Manan
Copy link to clipboard
Copied
ar myDoc = app.documents[0];
var myParas = myDoc.stories.everyItem().paragraphs.everyItem().getElements();
var myPage = myDoc.pages;
for(i=0; i<myParas.length; i++)
{
app.select(myParas[i]);
var paraStyleName=myDoc.selection[0].appliedParagraphStyle.name;
if (paraStyleName=="Style1")
{
app.selection[0].label = "TODO";
}
Copy link to clipboard
Copied
You said you wanted to set label on paragraphstyle but your code is trying to set it on paragraph. Also, I don't see you have even tried using my code, so their is nothing to suggest there.
Now the question is what exactly are you trying to achieve, tell in terms of your objective not api terms so that we can suggest some options.
-Manan
Copy link to clipboard
Copied
Hello Great people
Hope everyone doing good,
I want to create a script for selcting a pragraph style in Indesign and I wanto give a script lable that particular paragaraph style. Can any help on this? Please find the code which is I am using now
app.selection[0].paragraphStyles.item = "heading1";
Please guide me with the correct code.
Thanks in advance
Sandeep.
Copy link to clipboard
Copied
I have used this code to find a paagraph with a specific name by itarating through all paragraphs in the document. It's slow but it works.
--------------------------------------
Copy link to clipboard
Copied
Thank so much for your response I have used this code
ar myDoc = app.documents[0];
var myParas = myDoc.stories.everyItem().paragraphs.everyItem().getElements();
var myPage = myDoc.pages;
for(i=0; i<myParas.length; i++)
{
app.select(myParas[i]);
var paraStyleName=myDoc.selection[0].appliedParagraphStyle.name;
if (paraStyleName=="Style1")
{
app.selection[0].label = "TODO";
}
I am getting this error. Can you help me on this? I don't have coding knowledge.
Copy link to clipboard
Copied
Missed the first character when I copied the code. Sorry.
The first row should be:
var myDoc=app.documents[0];
Copy link to clipboard
Copied
If you want to start out from the applied paragraph style of a text selection, you could do:
app.selection[0].appliedParagraphStyle.insertLabel( "key" , "value" );
But that would not help much if you want to "label" paragraphs, formatted text, where a certain paragraph style is applied.
There is no "label" for text.
Instead:
You could use the property previewColor of a paragraph style that is not available from the GUI.
Marc Autret once built a full script around this feature, StyLighter:
https://indiscripts.com/post/2012/05/the-hidden-way-to-highlight-styles
StyLighter is still working with InDesign 2023.
You could highlight paragraphs in your text where a distinct paragraph style is applied to.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Now I am getting this error please find the code which I have used
function applyLabelToStyle1() {
var myDoc = app.documents[0];
var myParas = myDoc.stories.everyItem().paragraphs.everyItem().getElements();
var myPage = myDoc.pages;
for(var i=0; i<myParas.length; i++) {
app.select(myParas[i]);
var paraStyleName = myDoc.selection[0].appliedParagraphStyle.name;
if (paraStyleName == "MM_NL_Preis") {
app.selection[0].label = "TODO";
}
}
}
applyLabelToStyle1();
Copy link to clipboard
Copied
@Sandeep27041541kg7t are you even reading our posts? The reason for your error was already explained by @Laubender. You are not even trying what we are suggesting, then how can we help you?
-Manan
Copy link to clipboard
Copied
so Sorry I have tried multiple time, but I not fimiler with code I think it happing due to that.
please accept my apologies
Copy link to clipboard
Copied
I can understand you don't have much info about code. That is why I am asking to tell us about the problem you are trying to solve rather asking us to fix a piece of code that you picked from somewhere
-Manan
Copy link to clipboard
Copied
Hi @Sandeep27041541kg7t , If you check the Script Label panel, you will find that you can’t apply a label to a selected paragraph, which is why you get an error in your script when it selects a paragraph and tries to set a label.
If I select some text, I can’t edit the Script Label field:
But if I select a page item or a text frame, the Script Label field is editable. A paragraph’s parent text frame could have a label set—myParas[i].parentTextFrames[0].label = "TODO"—but not the paragraph itself:
Copy link to clipboard
Copied
Thanks you it is working. Great work.
Copy link to clipboard
Copied
Just curious, what was the need exactly?