🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #1705

Re: Javascript to iterate over every cell in a table

#1705
From: Dave_Saunders
Date: Tue, 27 Jan 2009 13:48
41 lines
2553 bytes
Bear in mind that every cell rule that is not on the edge of the table is shared. Thus, the look of any particular rule is determined by the order in which the cells are drawn, which is left to right then top to bottom.

Could this be the reason you're seeing what you're seeing?

Reapplying the cell styles might not do the job and the effect will be different depending on the order you do it.

I just created a pair of cell styles that won't live comfortably together. One applies a 1 point black rule left and right, the other applies a 0 point rule at left. These compete with each other. Apply them like a checkerboard and the result will depend on whether you go from top-left to bottom-right or the other direction.

This script demonstrates:

(function() { 
  if (app.documents.length > 0 
      && app.selection.length > 0) { 
    var myTable = findTable(app.selection[0]); 
    if (myTable == null) { return } 
    var myStyles = myTable.cells.everyItem().appliedCellStyle; 
    for (var j = myStyles.length -1; j >= 0; j--) { 
//~     for (var j = 0; myStyles.length > j; j++) { 
      if (myStyles[j].name != "None") { 
        myTable.cells[j].appliedCellStyle = myStyles[j]; 
      } 
    } 
  } 
}());

function findTable(obj) { 
  if (obj instanceof TextFrame) { 
    return obj.tables[0]; 
  } 
  while (obj.constructor.name != "Table") { 
    obj = obj.parent; 
    if (obj.constructor.name == "Application") { 
      return null; 
    } 
  } 
  return obj 
} // end findTable

Click in a table and run it. Change the loop to go the other way (just comment out the currently active for loop and activate the other one). If you get the same result, your cell styles are compatible and can coexist in adjacent cells, but if you don't the problem is your styles not InDesign behaving badly when rendering.

Dave
Technical Details
Message-ID: <59b7b20d.0@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossing
References: <59b7b20d.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,1dcd16a2120b1ad6
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Dave_Saunders@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: Javascript to iterate over every cell in a table
Message-ID: <59b7b20d.0@webcrossing.la2eafNXanI>
Date: Tue, 27 Jan 2009 05:48:39 -0800
References: <59b7b20d.-1@webcrossing.la2eafNXanI>
Lines: 52
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit