Copy link to clipboard
Copied
Hi
I would like to make multiples finds to tag my characters (Italic, Bold, AllCaps, SmallCaps, Underline...). To do so, i'm creating an Array, trying to store my findTextPreferences and using it in a "for" loop.
I've try different writing but nothing works.
Store like this :
caraFindPrefs[0][0] = "app.findGrepPreferences.fontStyle = 'Italic'"
Use like that in the "for" loop :
eval(caraFindPrefs[0]);
Store like this :
caraFindPrefs[0][0] = "fontStyle"
caraFindPrefs[0][1] = "Bold";
Use like that in the "for" loop :
app.findGrepPreferences.eval(caraFindPrefs[0]) = caraFindPrefs[0][1];
Or like that
app.findGrepPreferences.caraFindPrefs[0] = caraFindPrefs[0][1];
...
Do you have any advice to do this ?
Seb
Smallcaps?
Not possible.
It's not a property of findTextPreferences or findGrepPreferences.
An omission of the team that wrote ExtendScript functionality for InDesign.
For other property/value pairs you could build an array of objects:
...var myArray =
[
{fontStyle : "Italic"},
{fontStyle : "Bold"},
{underline : true }
];
var myResultArray = [];
var myScope = app.activeDocument;
for(var n=0; n<myArray.length; n++){
app.findTextPreferences = app.changeTextPreferences = null;
Copy link to clipboard
Copied
Hi,
try the following lines:
var curDoc = app.activeDocument;
var cStyleList = [
["Italic", "italic"],
["Bold", "bold"]
];
for ( var j = 0; j < cStyleList.length; j++ ) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.fontStyle = cStyleList
[0]; app.changeGrepPreferences.appliedCharacterStyle = cStyleList
[1]; curDoc.changeGrep();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
Copy link to clipboard
Copied
Hi Kai,
Thanks... but unfortunately "no" 🙂
Your solution is obvious as long as you apply only fontStyle, but what I'm looking for is to manage in the same loop, the ".position" or ".underline", ".strikethru"... properties ?
Copy link to clipboard
Copied
@LeftHand – then, how about working with the properties property?
You could apply several properties in one go.
var p = {
fontStyle : [ "Italic" , "Bold" ],
underline : [ true , false ]
};
app.findGrepPreferences = null;
app.findGrepPreferences.properties = {
fontStyle : p.fontStyle[1],
underline : p.underline[0]
};
Don't know why you like to do it this way, but something like the above is possible.
Also more directly and not so convoluted:
app.findGrepPreferences = null;
app.findGrepPreferences.properties = { fontStyle : "Bold", underline : true };
Uwe
Copy link to clipboard
Copied
Argh, I'm not explaining correctly 🙂
I want to find all my Italics then all my Bolds then all my underline, then all my smallcaps... but group it in one "for" loop to spare some script lines (the script is ok with multiples findText but would like to optimise it).
Seb
Copy link to clipboard
Copied
Smallcaps?
Not possible.
It's not a property of findTextPreferences or findGrepPreferences.
An omission of the team that wrote ExtendScript functionality for InDesign.
For other property/value pairs you could build an array of objects:
var myArray =
[
{fontStyle : "Italic"},
{fontStyle : "Bold"},
{underline : true }
];
var myResultArray = [];
var myScope = app.activeDocument;
for(var n=0; n<myArray.length; n++){
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.properties = myArray
; myResultArray
= myScope.findText(false); };
Uwe
Copy link to clipboard
Copied
Yes, will try this !
For smallcaps :
app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;
Copy link to clipboard
Copied
Thank you, missed that…
Ah. It seems it's Friday.
Uwe