Copy link to clipboard
Copied
HI,
I would like to find a bit of text in the document which have a character style and replace that bit of text with something else without removing the character style.
So for example on the screenshots here. The text saying "Pellentesque efficitur orci i" has the character style applied to it "guidebooklisting_name".
I would like to replace that text with "This is my real text" so the final result would look like this and would not loose the character style.
I hope that make sense : ) Thank you for your help,
Hi geza,
hope its helps!!
var myDoc = app.activeDocument;
app.findGrepPreferences.findWhat = "Find Text"
app.findGrepPreferences.appliedCharacterStyle ="guidebooklisting_name";
app.changeGrepPreferences.changeTo = "This is my real text";
myDoc.changeGrep();
Thanks,
Prabu G
Copy link to clipboard
Copied
Hi geza,
hope its helps!!
var myDoc = app.activeDocument;
app.findGrepPreferences.findWhat = "Find Text"
app.findGrepPreferences.appliedCharacterStyle ="guidebooklisting_name";
app.changeGrepPreferences.changeTo = "This is my real text";
myDoc.changeGrep();
Thanks,
Prabu G
Copy link to clipboard
Copied
It helps big time : ) Thank you!
I forgot to say I would like to do this regardless of the content what is in that style. But that is just a small change like this
Copy link to clipboard
Copied
Sorry to bother with it but I started to implement the code and now it throws errors.
Code is :
var myDoc = app.activeDocument;
app.findGrepPreferences.findWhat = "";
app.findGrepPreferences.appliedCharacterStyle = "guidebooklisting_name";
app.changeGrepPreferences.changeTo = "This is my real name";
myDoc.changeGrep();
return;
And it says
"Invalid value for set property appliedCharacterStyle. Expected String or Style or NothingEnum enumerator but received "guidebooklisting_name".
Driving me nuts ...
When I first tried everything worked just fine ... now it doesn't.
Any idea ?
Copy link to clipboard
Copied
Ah the problem was that I have grouped the styles and style must exist in the document in the root. Just that the error message is well ...
Copy link to clipboard
Copied
The charStyle is inside a group?
If yes, try to use:
app.activeDocument.characterStyleGroups.itemByName("name of the
group").characterStyles.itemByName("charStyle name");
Instead of "guidebooklisting_name";
If it's not inside group, just use:
app.activeDocument.characterStyles.itemByName("charStyle name");
Copy link to clipboard
Copied
Just relized that as well and we posted more less the same time. Thank you anyway : )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now