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

change table cell based on a textbox value, per page

New Here ,
Mar 16, 2017 Mar 16, 2017

Copy link to clipboard

Copied

Hi! I am totally new to InDesign scripting. I have some understanding of PHP but not much Javascript. My knowledge as of now is based on Keith Gilberts course at Lynda.

So I have this textbox with a header at the top of my page, and I have this table where one of the cells equals the header. I would like this cell to have a fillcolor. I have made this little script mixing two scripts I found here:find a text frame on the page with script label and here: How to apply a table cell style based on grep search? Thanks to the authors. As of now, I have managed the basic. The problem is that all the tables on every page gets filled with the last pages header rather than their respective pages headers. I have tried changing how much is inside my loop, but my unqualified guess would be that the problem is due to the fact that app.findTextPreferences is global and not per page.

Actually, I was kind of proud of myself managing to select a cell based on another objects value, but now I need some help to get all the way there and maybe learn some more scripting in the process. Anyone have any suggestions on how to solve this problem?

TOPICS
Scripting

Views

319

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
New Here ,
Mar 16, 2017 Mar 16, 2017

Copy link to clipboard

Copied

LATEST

here is my script:

var myDoc = app.activeDocument;

var pagesLength = myDoc.pages.length;

// Loop through all pages...

for ( var i = 0; i < pagesLength; i++ ) {

var myLabel = "topHeader",       // change to label

      myTextFrames =myDoc.textFrames.everyItem().getElements().slice(0),

      l = myTextFrames.length, 

      myVariable 

       

while (l--) { 

    if (myTextFrames.label != myLabel) continue; 

    myVariable = myTextFrames.contents; 

    break; // presuming there's only one "Foo" labeled frame on the page 

    // Otherwise you'll nead an array 

    } 

 

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.findWhat = myVariable;

var myFound = myDoc.findText()

for(i=0; i<myFound.length; i++)

{

    if(myFound.parent.constructor.name == "Cell")

    {

   myFound.parent.appliedCellStyle = "Yellow"

    //  var overrides = myFound.clearOverrides()          //this is the new line added in this content

  

    }

}

}

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