Copy link to clipboard
Copied
How does one use it?? i want to "distribute evenly" all the columns in all the tables in my story. Somehow i can't get it to work:
myStory.tables.everyItem().columns[0].redistribute(HorizontalOrVertical.HORIZONTAL) doesn't seem to work.
Vamitul
rows[0]? how does that makes any sense? Nop, see http://forums.adobe.com/message/4193947#4193947
anyway, that means i got no way of using everyItem. Where's you imagination Today?
Something like
d = app.documents[0];
myTable = d.stories.everyItem().tables.everyItem();
t = d.stories.everyItem().tables[0].getElements();
myTable.columns[0].redistribute(HorizontalOrVertical.VERTICAL,t[0].rows[0])
Trevor
Copy link to clipboard
Copied
Hi,
I don't own cs6 (so I can't test it) but redistribute is described as a method for a range of columns.
Copy link to clipboard
Copied
it's on CS5, and ... i'm lost.. it's a column method, but that's about as far as i can get with it..
Copy link to clipboard
Copied
myTable.columns[0].redistribute(HorizontalOrVertical.VERTICAL,myTable.rows[0])
Is the basic format
Trevor
Copy link to clipboard
Copied
rows[0]? how does that makes any sense?
anyway, that means i got no way of using everyItem.
Copy link to clipboard
Copied
Vamitul
rows[0]? how does that makes any sense? Nop, see http://forums.adobe.com/message/4193947#4193947
anyway, that means i got no way of using everyItem. Where's you imagination Today?
Something like
d = app.documents[0];
myTable = d.stories.everyItem().tables.everyItem();
t = d.stories.everyItem().tables[0].getElements();
myTable.columns[0].redistribute(HorizontalOrVertical.VERTICAL,t[0].rows[0])
Trevor
Copy link to clipboard
Copied
i think adobe wrote the code for the "redistribute" method on 1 April, because it makes 0 sense.
why on earth is VERTICAL??
and why is the range of distributing columns a row?!?!
it works, but ??
ps. if you don't mind, walk me through your code a bit, because apparenty i'm very slow today (spend 2 hours today tying to debug a script, just to realise that the problem was with the document itself - it seems you can't have a paragraph style group named with the same name a a paragraph style -).
so..
myTable is a colection of every table in the document
t is what? an array containg the first table in the document? what's with the getElements there?
so.. redistribute the columns of the tables in the document VERTICALY (that actualy means horizontal), using as "the last Column in the range" (quote from the object reference) the first row of the first table in the document?!?!?
please shoot me!!!!
Copy link to clipboard
Copied
I'm off for a sleep, will try to get back tonight
ZZZZZzzzzzz
Copy link to clipboard
Copied
Hhm, a little bug
My above script will fail if t[0] has less columns in it that any of the other tables in the doc.
But after a several hundred attempts I found this will work
myTables = app.documents[0].stories.everyItem().tables.everyItem();
myTables.rows[0].redistribute(HorizontalOrVertical.VERTICAL); // changed from
columns[0] to row[0] and got rid of the range
That will only fail if any of the tables in the document have only 1 column (so they it can't be redistributed).
In such you could forego on your pride and iterate through them.
Back to the original script and t[0]
The idea was to set the range to the first table row in the document so it would do the lot.
Well you might think that the above line is not so clear, but it is a perfect reflection of my understanding on the topic (or lack of understanding)
Trevor
Copy link to clipboard
Copied
nope.. error: Invalid parameter
Copy link to clipboard
Copied
So you must have a table with only one column in it in the top row.
Anyway this should deal with MOST cases and only does a very little bit of write iterating so should still be very quick
// Script by Trevor http://forums.adobe.com/message/5225003#5225003
app.doScript("main()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Table Redistribution");
function main()
{
var myOneRowTables = [],
n = 0,
mt = app.documents[0].stories.everyItem().tables.everyItem().getElements(), l = mt.length;
myTables = app.documents[0].stories.everyItem().tables.everyItem();
while (l--) if (mt
.rows[0].cells.length < 2 && mt .rows.length > 1) {
myOneRowTables [n++] = mt
; mt
.rows[0].cells[0].split (HorizontalOrVertical.VERTICAL); }
myTables.rows[0].redistribute(HorizontalOrVertical.VERTICAL); // changed from columns[0] to row[0] and got rid of the range
while (n--)
{
myOneRowTables
.rows[0].cells[0].merge (myOneRowTables .rows[0].cells[1]) myOneRowTables
.rows.itemByRange(1,-1).redistribute(HorizontalOrVertical.VERTICAL); }
}
Copy link to clipboard
Copied
@Trevor – I still would like "shaking the tree" with my method.
That is working in every case:
//Redistribute all tables without redistribute() method:
var myTables = app.documents[0].stories.everyItem().tables.everyItem().getElements();
for(var n=0;n<myTables.length;n++){
//Expand the width of the table a bit:
myTables
.width = ++myTables .width; //Shrink it back (in the process all columns will be redistributed evenly in width):
myTables
.width = --myTables .width; };
Uwe
Copy link to clipboard
Copied
Uwe, I agree with you that you method is a lot safer and wouldn't be concered what's going to be with CS12.
So here's the compromise see the catch at the bottom.
Safe and Swift (I think)
// Script by Trevor http://forums.adobe.com/message/5225003#5225003
app.doScript("main()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Table Redistribution");
function main()
{
var myOneRowTables = [],
n = 0,
mt = app.documents[0].stories.everyItem().tables.everyItem().getElements(), l = mt.length;
myTables = app.documents[0].stories.everyItem().tables.everyItem();
while (l--) if (mt
.rows[0].cells.length < 2 && mt .rows.length > 1) {
myOneRowTables [n++] = mt
; mt
.rows[0].cells[0].split (HorizontalOrVertical.VERTICAL); }
myTables.rows[0].redistribute(HorizontalOrVertical.VERTICAL);
while (n--)
{
myOneRowTables
.rows[0].cells[0].merge (myOneRowTables .rows[0].cells[1]) try {myOneRowTables
.rows.itemByRange(1,-1).redistribute(HorizontalOrVertical.VERTICAL);}; catch (bug) {myOneRowTables
.width = ++myOneRowTables .width; myOneRowTables .width = --myOneRowTables .width;}; }
}
I could find any fail cases with this one.
Copy link to clipboard
Copied
I hope you guys know i'we 'fixed' the problem about 3 versions of my script ago (that means this morning... any more revisions and i'll go completly nuts), using Uwe's hack.
I guess if it works i shoudn't complain, but this is by far the largest automation project i'we ever done (getting close to 80000 lines of code so far) and getting stuck on something as simple as this got me realy pissed. I fell is just one hack too many.
Anyway, thank you all. I got to say that this forum is one of the awesomest communities ever.
Copy link to clipboard
Copied
I took out an accidentally left in line from the above script
Copy link to clipboard
Copied
@Vamitul – alternatively you can do the following without redistribute():
//Cheap trick without redistribute():
//One Table selected:
var myTable = app.selection[0];
//Expand the width of the table a bit:
myTable.width = ++myTable.width;
//Shrink it back (in the process all columns will be redistributed evenly in width):
myTable.width = --myTable.width;
Uwe
Copy link to clipboard
Copied
thanks uwe.
I usualy don't like to use this kind of tricks because you never know if they will still work in the next version of indesign.
Plus, i wanted to distribute all the tables in my story, and i wanted to do it in one line (let's say it was a matter of personal pride...)