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

GREP/JS

Guide ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

Why the javscript omits slashes, when i wrote something in GREP. Is it possible to include slashes using JS?

TOPICS
Scripting

Views

1.3K

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
LEGEND ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

You need to escape your slashes in scripts.

"\" becomes "\\" and "\\" becomes "\\\\"...

Harbs

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
Guide ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

Hi,

Thanks for yur quick reply. Thats working perfectly. I want to apply a character style. I got a script from another person.

var myParaStyles = app.activeDocument.allParagraphStyles;
for (var i = 0; i < myParaStyles.length; i++){
    try{
        var myParaGrep = myParaStyles.nestedGrepStyles.add();
        myParaGrep.grepExpression = "{put GREP expression}";
        myParaGrep.appliedCharacterStyle = "{put Character Style Name}";
    }
    catch(_){}
}

But it does not take the character style. Whats wrong?

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 ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

Just to make sure -- Are you replacing this correctly with the character style name? Does that style name exist? Is it in a group?

{put Character Style Name}

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
Guide ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

Yes, am copy and paste the character style name. But it does not apply.

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 ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

you cannot submit a string into a nested grepStyle.

a quick fix would be:

change

        myParaGrep.appliedCharacterStyle = "{put Character Style Name}";

to

        myParaGrep.appliedCharacterStyle = app.activeDocument.characterStyles.itemByName("{put Character Style Name}");

this won't work with characterStyleGroups

gregor

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
Guide ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

Excellent, it's working. Another one, my GREP code is,

\S+[[:punct:]]"$

How can i give that closing quotes?

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 ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

Use the regular code ~} for curly double closing quotes.

Grefel:

appliedCharacterStyleCharacterStyle
String
r/wThe character style applied to the text. Can also accept: String.

Ouch!

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
Advisor ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

Yes, that's my snippet.

Thanks Jongware for pointing out that appliedCharacterStyle can accept String also.

I tested snippet and it worked just fine for me.

Also I put those commenting strings just like placeholders.

--

tomaxxi

http://indisnip.wordpress.com

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 ,
Dec 04, 2010 Dec 04, 2010

Copy link to clipboard

Copied

hey tomaxxi + jongware,

string is not working here. with a german indesign cs5 + cs4 and windows 64 bit i get an:

Error: Invalid value for set property 'appliedCharacterStyle'. Expected CharacterStyle or String, but received "ziffer".

character style 'ziffer' is in place!

by the way: i think you don't really need a try/catch just start the for-loop at 1 omitting the [No Paragraph Style] style.

var _dok = app.activeDocument;
var _absFormate = _dok.allParagraphStyles;
for (var i = 1; i < _absFormate.length; i++) {
    var _format = _absFormate.nestedGrepStyles.add();
    _format.grepExpression = "//d";
    _format.appliedCharacterStyle = getCharacterStyle("ziffer");
}


function getCharacterStyle (_name) {
    for (var i = 0; i < _dok.allCharacterStyles.length; i++) {
        if (_dok.allCharacterStyles.name == _name ) return _dok.allCharacterStyles;
    }
    return null;
}

gregor

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 ,
Dec 04, 2010 Dec 04, 2010

Copy link to clipboard

Copied

Gregor,

This error message:

> Error: Invalid value for set property 'appliedCharacterStyle'. Expected CharacterStyle or String, but received "ziffer".

is misleading as it suggests that you can set the style with a string. But you can't: you have to use an object, as in

. . . = myDoc.characterStyles.item ("ziffer");

Peter

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 ,
Dec 04, 2010 Dec 04, 2010

Copy link to clipboard

Copied

hey peter,

we have been talking about this issue - the documentation seems to be wrong. BUT tomaxxi's and jongware's indesign instances are happy with a string... anyway we can close this topic ... a nested GREP style is a minor issue.

gregor

--

http://www.indesignblog.com

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
Guide ,
Dec 04, 2010 Dec 04, 2010

Copy link to clipboard

Copied

LATEST

Hi everybody,

Thanks for your valuable anwers.

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