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

multiple findTextPreferences in a loop

Explorer ,
Mar 21, 2014 Mar 21, 2014

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

TOPICS
Scripting

Views

861

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

correct answers 1 Correct answer

Community Expert , Mar 21, 2014 Mar 21, 2014

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;

 

...

Votes

Translate

Translate
Enthusiast ,
Mar 21, 2014 Mar 21, 2014

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;

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
Explorer ,
Mar 21, 2014 Mar 21, 2014

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 ?

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 ,
Mar 21, 2014 Mar 21, 2014

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

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
Explorer ,
Mar 21, 2014 Mar 21, 2014

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

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 ,
Mar 21, 2014 Mar 21, 2014

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

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
Explorer ,
Mar 21, 2014 Mar 21, 2014

Copy link to clipboard

Copied

Yes, will try this !

For smallcaps :

app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;

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 ,
Mar 21, 2014 Mar 21, 2014

Copy link to clipboard

Copied

LATEST

Thank you, missed that…
Ah. It seems it's Friday.

Uwe

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