Skip to main content
Inspiring
August 8, 2019
Answered

Find Paragraph-Style-name in quotes

  • August 8, 2019
  • 2 replies
  • 2092 views

Hi everybody!

It is a tiny little mess I can't solve this problem:

In an InDesign document somebody created the paragraph-style "Menge" (amount). It's the style for the number of pieces in a table. And this somebody put the name in QUOTES!!! I don´t know why.

Now I want to search for this and other styles and change the font. Unfortunately I didn´t found a way yet.

I tried it like this:

var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.itemByName("\"Menge\"");
alert(myStyle.isValid);

... and like this:

var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.itemByName('"Menge"'); //

alert(myStyle.isValid);

... or like that:

var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.itemByName('^"Menge^"'); //

alert(myStyle.isValid);

If I change the name to another, without quotes, it will be found.

To change that name is not an option, because I get the dokuments every time from somebody who is working with them.

Is there any way to deal with that?

This topic has been closed for replies.
Correct answer Sunil Yadav

you have to put style name in single quotes and your style name is "Menge"

var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.item('"Menge"');

alert(myStyle.isValid);


cmoke73 It seems a quite tricky to get in one line.

So I would suggest don't get stuck there.

Try this:

var myDoc = app.documents[0];

var groupStyleName = 'Formatgruppe 1';

var myStyleName = '"Menge"';

var myStyle = findGroupStyle(groupStyleName, myStyleName);

if(myStyle != null){

    alert(myStyle.name);

    }

else{

    alert("Style does not exists !!!");

    }

///////////////////////////////////

function findGroupStyle(groupStyleName, myStyleName){

    for(var gp = 0; gp < myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles.length; gp++){

        if(myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles[gp].name == myStyleName){

            return myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles[gp];

            }

        }

    return null;

    }

Best

Sunil

2 replies

cmoke73Author
Inspiring
August 8, 2019

I'm not that good at scripting. But what about the idea to search with a regular expression-function (RegExp). Is that possible?

Community Expert
August 8, 2019

Hi cmoke73 ,

yes. You can find a style or a style group where you are looking for one part of a name.

But first I suggest you'll see into the exact name of that style group and how it is exactly composed of glyphs.

Maybe there are some unusual glyphs used for the quotation marks ( or whatever the ones are ).

Run the following code that will add a new text frame to the first page of your document.

The contents of the frame are all names for all style groups in the root of your paragraph styles panel.

The language for the text is set to "No Language".

var doc = app.documents[0];

var newTextFrame = doc.pages[0].textFrames.add

(

    {

        geometricBounds : [0,0,100,100] ,

        parentStory : { appliedLanguage : doc.languages[0] } ,

        contents : doc.paragraphStyleGroups.everyItem().name.join("\r")

    }

);

After that inspect the glyphs that make the quotes.

Here a sample screenshot from the result I did with a document that uses some strange kind of quotes in the names:

As you can see from my Story Editor Window and compare this with the look of the names in my paragraph styles panel some look similar enough, but in fact are not. Otherwise I could not have created the style group.

The third and the first one listed look quite the same.

But apparently they are not!

Test my code snippet and come back if you found the right unicode value(s) for the two quotes.

FWIW: Both quotation marks could be different and could be composed of one or two glyphs.

If so list the unicode values for every single glyph surrounding Menge.

Regards,
Uwe

EDIT: Removed one line of the code that was not necessary.

cmoke73Author
Inspiring
August 8, 2019

Hi Laubender.

Many thanks for your effort! Your detailed explanation is very helpful as well.

A little remark: the name is not the name of a group but for a paragraph-style IN a group. But it doesn´t really make a difference.

The Unicode for the opening quote is 0x201E and for the closing one it is 0x201C.

payalm68947498
Inspiring
August 8, 2019

Hello,

    try this to find style in document


var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.item('"Menge"'); 

alert(myStyle.isValid);

cmoke73Author
Inspiring
August 8, 2019

Hi.

I forgot, that was the fourth trial.

but thanks

And if I do this:

var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.itemByName(""Menge"");

... the word "Menge" becomes part of the code and on the left side and the right side are two/two quoted nothings.

payalm68947498
Inspiring
August 9, 2019

you have to put style name in single quotes and your style name is "Menge"

var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.item('"Menge"');

alert(myStyle.isValid);