Copy link to clipboard
Copied
Why the javscript omits slashes, when i wrote something in GREP. Is it possible to include slashes using JS?
Copy link to clipboard
Copied
You need to escape your slashes in scripts.
"\" becomes "\\" and "\\" becomes "\\\\"...
Harbs
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?
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}
Copy link to clipboard
Copied
Yes, am copy and paste the character style name. But it does not apply.
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
Copy link to clipboard
Copied
Excellent, it's working. Another one, my GREP code is,
\S+[[:punct:]]"$
Copy link to clipboard
Copied
Use the regular code ~} for curly double closing quotes.
Grefel:
appliedCharacterStyle | CharacterStyle String | r/w | The character style applied to the text. Can also accept: String. |
Ouch!
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
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
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
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
Copy link to clipboard
Copied
Hi everybody,
Thanks for your valuable anwers.