🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #2171

Re: [JS CS3] Merging table columns

#2171
From: Peter Kahrel
Date: Sat, 10 Jan 2009 10:09
20 lines
1813 bytes
Michael,

You can optimise two things in your code. First, avoid referring to collections (such as myTable.rows and myTable.columns) repeatedly. Instead, create arrays from collections. Earlier this week this was discussed here: Harbs, "[JS] :: [CSX] - PageItem Stacking Order" #15, 6 Jan 2009 11:23 am </webx?14@@.3bbf275d.59b767cf/14> . see especially the reference to Kris Coppetier's article in Harbs's post, who explains that each time you refer to a collection, InDesign rebuilds it -- so you can imagine that rebuilding a big table such as yours causes the script to run for hours.

In your case, instead of referring to myTable.rows.length-1, do this:

myRows = myTable.rows.everyItem().getElements();
myRows_length = myRows.length-1;
for (var f = myRows; . . .

Secondly, you needn't refer to myRows[f].columns[...].cells[...]: myRows[...].cells[...] will do too. So your script coulkd look like this:

myRows = myTable.rows.everyItem().getElements(); 
myRows_length = myRows.length-1; 
for (var f = myRows_length; f >= 0; f--) 
   myRows[f].cells[3].merge (myRows[f].cells[4]);

This will probably speed things up.

Peter
Technical Details
Message-ID: <59b779d3.0@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.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: "Peter Kahrel" <kahrel@kahrel.plus.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: [JS CS3] Merging table columns
Message-ID: <59b779d3.0@webcrossing.la2eafNXanI>
Date: Sat, 10 Jan 2009 02:09:38 -0800
References: <59b779d3.-1@webcrossing.la2eafNXanI>
Lines: 19
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Original-Lines: 27