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

Set label on a paragraphstyle

Community Beginner ,
Jul 27, 2023 Jul 27, 2023

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.

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

Community Expert , Jul 27, 2023 Jul 27, 2023

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:

 

Screen Shot 37.png

 

 

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

...
Translate
Community Expert ,
Jul 27, 2023 Jul 27, 2023

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

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 Beginner ,
Jul 27, 2023 Jul 27, 2023

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.

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 ,
Jul 27, 2023 Jul 27, 2023

Share the exact code you used and also tell how did you verify that the label was not set.

-Manan

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 Beginner ,
Jul 27, 2023 Jul 27, 2023

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";
}

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 ,
Jul 27, 2023 Jul 27, 2023

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

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 Beginner ,
Jul 27, 2023 Jul 27, 2023

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.

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 Beginner ,
Jul 27, 2023 Jul 27, 2023

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.

--------------------------------------

var 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=="Title1")
{
what you want to do when finding the 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
Community Beginner ,
Jul 27, 2023 Jul 27, 2023

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.

Sandeep27041541kg7t_0-1690456323984.png

 

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 Beginner ,
Jul 27, 2023 Jul 27, 2023

Missed the first character when I copied the code. Sorry.
The first row should be:

var myDoc=app.documents[0];

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 ,
Jul 27, 2023 Jul 27, 2023

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 )

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 Beginner ,
Jul 27, 2023 Jul 27, 2023

Sandeep27041541kg7t_0-1690460855256.png

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();

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 ,
Jul 27, 2023 Jul 27, 2023

@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

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 Beginner ,
Jul 27, 2023 Jul 27, 2023

so Sorry I have tried multiple time, but I not fimiler with code I think it happing due to that.

please accept my apologies

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 ,
Jul 27, 2023 Jul 27, 2023

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

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 ,
Jul 27, 2023 Jul 27, 2023

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:

 

Screen Shot 37.png

 

 

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:

Screen Shot 38.png

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 Beginner ,
Jul 27, 2023 Jul 27, 2023

Thanks you it is working. Great work.

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
People's Champ ,
Jul 28, 2023 Jul 28, 2023
LATEST

Just curious, what was the need exactly?

 

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