Copy link to clipboard
Copied
For example, the following seems to represent all the tables in the document.
If I want to change only the width of all the tables in the current selected textFrame, how do I change it.
Confused again.
main();
function main() {
var myTables = app.activeDocument.textFrames.everyItem().tables.everyItem().getElements(),
len = myTables.length,
i, col, parentWidth, factor;
for (i = 0; i < len; i++) {
// Get the width of the text box that the form belongs to and divide it by the width of the form to get the zoom ratio.
parentWidth = myTables[i].parent.geometricBounds[3] - myTables[i].parent.geometricBounds[1];
factor = parentWidth / myTables[i].width;
//Nest a for-loop that applies scaling to each column width
for (col = 0; col < myTables[i].columns.length; col++) {
myTables[i].columns[col].width *= factor;
}
}
}
And then there are these, which have never made sense.
Please advise, thank you.
All open documents.
Currently open document.
The currently selected textFrame.
All text boxes in the current document.
All tables in the current document.
The currently selected textFrame (article?) All tables in the current document.
The currently selected table.
The currently selected row.
All cells in the currently selected row.
The currently selected cell.
The currently selected row.
All the frames in the current text.
The current textFrame(article?) All the charts in the current text box (article?).
The currently selected frame.
@dublove said: "… If I want to change only the width of all the tables in the current selected textFrame, how do I change it."
Hi @dublove ,
you could address the texts[0] text object of the text frame and look after all tables and write them to an array you could later loop to change the width:
var selectedTextFrame = app.selection[0];
var tablesOfTextFrameArray = selectedTextFrame.texts[0].tables.everyItem().getElements();
alert( "Number of tables:" +"\r"+ tablesOfTextFrameArray.length );
...
Copy link to clipboard
Copied
You should be able to change "activeDocument.textFrames" to "selection" and get what you want as long as that text frame with the table is selected.
Copy link to clipboard
Copied
Is there a specific program?
I'd actually prefer to know how these codes below are represented.
Thank you very much.
Copy link to clipboard
Copied
@dublove said: "… If I want to change only the width of all the tables in the current selected textFrame, how do I change it."
Hi @dublove ,
you could address the texts[0] text object of the text frame and look after all tables and write them to an array you could later loop to change the width:
var selectedTextFrame = app.selection[0];
var tablesOfTextFrameArray = selectedTextFrame.texts[0].tables.everyItem().getElements();
alert( "Number of tables:" +"\r"+ tablesOfTextFrameArray.length );
Or you could address them all directly to change the width of the tables or to change the width of an individual column:
var selectedTextFrame = app.selection[0];
selectedTextFrame.texts[0].tables.everyItem().width = "200 mm";
See DOM documentation, tables and columns have a width property:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Table.html
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Column.html
But be aware that tables in overset text will not change.
Ran the script snippet above that uses the width property of the table object and set it to "200 mm":
Screenshot 1 where there are two tables visible and one in overset text of different widths:
After running the script the two visible table's width is now 200 mm:
When I change now the height of the text frame so that the third table in overset text is now visible, one can see that it has its original width:
We could try to modify the code a bit to get all tables of the parent story of the selected text frame:
var selectedTextFrame = app.selection[0];
selectedTextFrame.parentStory.texts[0].tables.everyItem().width = "200 mm";
The final result is that all tables, also the one in overset text, changed the width:
Regards,
Uwe Laubender
( Adobe Community Expert )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now