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

object contains no text for Find/Change

Engaged ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

I'm trying to run this script to select text if it is found but it says there no text even though I've wrapped it in an if statement.

function seeSection () { 

    app.findGrepPreferences=app.changeGrepPreferences=null; 

  app.findGrepPreferences.findWhat= "the (section\\s+?\\d+?[\\.\\d+]?)"; 

     app.changeGrepPreferences.changeTo="$1";

    app.changeGrepPreferences.appliedCharacterStyle="cross reference";

      if (app.activeDocument.findText()){

          found.select();

          };

   var changes1 = app.activeDocument.changeGrep();

    if (changes1.length===1){

alert(changes1.length+" instance of 'the section' was changed to 'section'.");

}else{

   alert(changes1.length+" instances of 'the section' were changed to 'section'.");

  }

    };

TOPICS
Scripting

Views

640

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

Engaged , Sep 26, 2016 Sep 26, 2016

Is your post at find/change script highlight found text not the same question??

Votes

Translate

Translate
Guide ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

Javascript execute line by line. So after the changed text it wont find. I just commented the changeTo line. Try this:

function seeSection () {

    app.findGrepPreferences=app.changeGrepPreferences=null;

  app.findGrepPreferences.findWhat= "the (section\\s+?\\d+?[\\.\\d+]?)";

//~      app.changeGrepPreferences.changeTo="$1";

    app.changeGrepPreferences.appliedCharacterStyle="cross reference";

      if (app.activeDocument.findText()){

          found.select();

          };

   var changes1 = app.activeDocument.changeGrep();

    if (changes1.length===1){

alert(changes1.length+" instance of 'the section' was changed to 'section'.");

}else{

   alert(changes1.length+" instances of 'the section' were changed to 'section'.");

  }

    };

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
Guide ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

also using greppreference should be

app.activeDocument.findGrep()

not app.activeDocument.findText()

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
Engaged ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

Isn't changeTo just a specifier? It hasn't been resolved yet so it shouldn't do anything with that information until I say changeGrep() or findGrep()?

Also,

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
Guide ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

Ah..yes i missed..but did you tried this one

app.activeDocument.findGrep()

not app.activeDocument.findText()

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 ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

What does 'found' mean in your function? It's not bound in any way.

You set the Grep options, then you do findText()

You probably want something along the lines of

found = app.activeDocument.findText();

if (found.length > 0) {

  found[0].select();

}

findText() and findGrep() return an array.

Peter

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
Engaged ,
Sep 26, 2016 Sep 26, 2016

Copy link to clipboard

Copied

Is your post at find/change script highlight found text not the same question??

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
Engaged ,
Sep 27, 2016 Sep 27, 2016

Copy link to clipboard

Copied

LATEST

Yes you're right, now that I understand the problem, my other post answers this question.

I was trying to access the found text in the findWhat field!

Thanks for all your comments, I'm starting to understand the InDesign DOM more

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