Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

How to Change table cell based on a textbox value, per page?

Return to Member Forum

  • Author
    Posts
    • #92902
      Anonymous
      Inactive

      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, but I am kind of on deep water here.

      Actually, I was kind of proud of myself managing to select a cell based on another objects value, but after two days of banging against the wall I kind of got down again. 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?

    • #92903
      Anonymous
      Inactive

      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[l].label != myLabel) continue;
      myVariable = myTextFrames[l].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[i].parent.constructor.name == “Cell”)
      {

      myFound[i].parent.appliedCellStyle = “Yellow”
      // var overrides = myFound[i].clearOverrides() //this is the new line added in this content

      }
      }
      }

    • #92912

      Are, without studying your code: You are right! “myDoc.findText()” find everything in the document and not per page. The problem is: There is no “per page”-option via scripting. So you need to loop through all pages, find your labeled textframe on the current page, find one or more tables on the current page. Then you have the choice, either compare the contents of the cells or do it with fc in the whole table.

      Kai

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
Forum Ads