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

Set label on a paragraphstyle

Community Beginner ,
Jul 27, 2023 Jul 27, 2023

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.

TOPICS
Scripting

Views

334

Translate

Translate

Report

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

...

Votes

Translate

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

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

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

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

Votes

Translate

Translate

Report

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

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.

Sandeep27041541kg7t_0-1690456323984.png

 

Votes

Translate

Translate

Report

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

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];

Votes

Translate

Translate

Report

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

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 )

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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:

 

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks you it is working. Great work.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Just curious, what was the need exactly?

 

Votes

Translate

Translate

Report

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