🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #1144

Re: [JS CS3] Merging table columns

#1144
From: Dave_Saunders
Date: Wed, 18 Feb 2009 01:48
72 lines
2594 bytes
I've just done some time testing with CS4 and found the following:

table = app.documents[0].stories[0].tables[0]; 
start = new Date(); 
for (var n = 0; 100 > n; n++) { 
  cells = table.cells; 
  for (var j = 0; cells.length > j; j++) { 
    cells[j].contents = "James"; 
  } 
} 
end = new Date(); 
alert(end - start);

takes just about the same time to run as:

table = app.documents[0].stories[0].tables[0]; 
start = new Date(); 
rowCount = table.rows.length; 
columnCount = table.columns.length; 
for (var n = 0; 100 > n; n++) { 
  for (var c = 0; columnCount > c; c++) { 
    for (var r = 0; rowCount > r; r++) { 
      table.cells.item(c + ":" + r).contents = "Harry"; 
    } 
  } 
} 
end = new Date(); 
alert(end - start);

While this version takes about half as long again:

table = app.documents[0].stories[0].tables[0]; 
start = new Date(); 
rowCount = table.rows.length; 
columnCount = table.columns.length; 
for (var n = 0; 100 > n; n++) { 
  for (var c = 0; columnCount > c; c++) { 
    for (var r = 0; rowCount > r; r++) { 
      table.rows[r].cells[c].contents = "Harry"; 
    } 
  } 
} 
end = new Date(); 
alert(end - start);

None of which is particularly surprising. But when I compared the following two scripts, I was astonished by the result:

table = app.documents[0].stories[0].tables[0]; 
start = new Date(); 
rowCount = table.rows.length; 
columnCount = table.columns.length; 
for (var n = 0; 100 > n; n++) { 
  table.cells.everyItem().contents = "Harry"; 
} 
end = new Date(); 
alert(end - start);



table = app.documents[0].stories[0].tables[0]; 
start = new Date(); 
rowCount = table.rows.length; 
columnCount = table.columns.length; 
for (var n = 0; 100 > n; n++) { 
  table.cells.itemByRange(0, -1).contents = "George"; 
} 
end = new Date(); 
alert(end - start);

The latter, using itemByRange was about a third faster than using everyItem(). 1800 milliseconds to 2700 on a 4 x 10 table.

Dave
Technical Details
Message-ID: <59b779d3.6@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!newshub.sdsu.edu!webcrossing
References: <59b779d3.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,fcf8b6c8e9285d5b
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!news1.google.com!news2.google.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: [JS CS3] Merging table columns
Message-ID: <59b779d3.6@webcrossing.la2eafNXanI>
Date: Tue, 17 Feb 2009 17:48:01 -0800
References: <59b779d3.-1@webcrossing.la2eafNXanI>
Lines: 62
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit