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

GREP/JS

Guide ,
Dec 03, 2010 Dec 03, 2010

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

TOPICS
Scripting
1.7K
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
LEGEND ,
Dec 03, 2010 Dec 03, 2010

You need to escape your slashes in scripts.

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

Harbs

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

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?

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

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}

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

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

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

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

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

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

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

How can i give that closing quotes?

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

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!

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

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

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

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

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

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

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

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

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

Hi everybody,

Thanks for your valuable anwers.

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