• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is there a script to set all columns of a table at once to a specified width value?

Advocate ,
Aug 14, 2024 Aug 14, 2024

Copy link to clipboard

Copied

Is there a script to set all columns of a table at once to a specified width value?
I have almost 50 tables with column widths that need to be adjusted to the same value.
I can only use the align to reference line method for now, as too many is quite time consuming.
It would be nice to have a script to set it.
It can set how many columns there are and specify the width of each column.

Thank you.

6969.jpg

TOPICS
Bug , How to , Performance , Scripting

Views

891

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Guru , Aug 14, 2024 Aug 14, 2024

Check out the Auto Column script.

Votes

Translate

Translate
Engaged , Aug 15, 2024 Aug 15, 2024

I have used this script for some years to format tables to a consistent size (I'm not sure where it came from, sorry).

 

It only does a single table at a time, but it is still pretty quick to do a whole lot as it just requires the table to be selected and then the script run.

 

You set the column widths in the 'var myWidths = [60, 10, 10, 10];' line of the script so it remembers the last figures you entered.

 

var myDoc = app.activeDocument;
var myWidths = [60, 10, 10, 10];
for(var T=0; T < myDoc.textFr
...

Votes

Translate

Translate
Guru ,
Aug 14, 2024 Aug 14, 2024

Copy link to clipboard

Copied

Check out the Auto Column script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

This script does not store the last settings?
It's a pain to have to re-enter it every time

A book may have 2-5 different tables.
It would be nice to be able to store 2-5 different scenarios

exmple:

Tab-A
Tab-B
Tab-C
Tab-D
Tab-E

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

@dublove

 

My ID-Tasker - you can save "table presets" as different Tasks and then run on current document - or whole servers full of INDD documents. 

 

You can either filter tables to be processed first - by number of columns/rows, formatting, etc. or define condition at the beginning of the Task - table will be skipped if condition hasn't been met. 

 

But it's PC only and full version is not free. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 14, 2024 Aug 14, 2024

Copy link to clipboard

Copied

Simple enough, assuming all tables in the doc all have 7 columns as illustrated in your screenshot: 

var widths = [
    "3 mm",
    "5 mm",
    "5 mm",
    "1 mm",
    "3 mm",
    "5 mm",
    "5 mm",
];

var i = widths.length;
while(i--) {
    app.activeDocument.stories.everyItem().tables.everyItem().columns.item(i).width = widths[i];
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 14, 2024 Aug 14, 2024

Copy link to clipboard

Copied

?

Is there a full working script?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

quote

?

Is there a full working script?


By @dublove

 

This is a full working script - but it will resize columns in all tables in the document to the same width - specified by the array at the beginning of the code. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

Nothing of value.

The github resource shared by Kasyan Servetsky is available, just not perfect.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

Nothing of value? 

 

Friend, you come here regularly looking for help, but you often are dismissive or argumentative regarding said help. 

 

The script I posted works on a single document containing tables of exactly 7 columns. If your doc had tables all of 8 columns, then you'd add a new entry to the array. As stated it would fail if there was a table that had fewer columns then found in the array.

 

The other script appears to work only on a single table, which doesn't solve your problem of processing 50 tables at once. 

 

Could it be modified or enhanced? Sure. But it is not worthless, and I generally am compensated monetarily for indepth, custom development work. My time is valuable. If you need help installing a script you found online, then read this: https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post/

 

I hesitated writing this script given your past interactions in this forum. Should have trusted my gut, I suppose. I don't particularly enjoy waking up to see my efforts dismissed out of hand. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

Thank you for saying so much, you've worked hard.

Maybe I'll just say that this is better, I've found that I can store data.
You just can't store multiple sets of data.

https://github.com/gsingelmann/indd_autocolumn

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

You just can't store multiple sets of data.

 

Hi @dublove , As @brian_p_dts suggests, I don’t think you can expect anyone here to develop a complex script for you at no cost.

 

It is possible to save complex dialog results by writing and reading an XML file. Here’s a simple example that saves the entered values for 2 measurement fields—the xml file is saved in the script’s parent directory:

 

 

//this script’s folder
var f = File($.fileName).parent + "/defaults.xml";

//if there’s no XML set a default
var xml = readXML(f)
if (xml == "") {
    xml = XML( "<dialog><values><top>0</top><bottom>0</bottom></values></dialog>")
}

//get the top and bottom values from XML
//will be 0 if an xml file does not exist
var tv = Number(xml.values.top);
var bv = Number(xml.values.bottom);

var t, b;
makeDialog();
function makeDialog(){
    var d = app.dialogs.add({name:"Enter Values", canCancel:true});
    with(d.dialogColumns.add()){
        staticTexts.add({staticLabel:"Cell 1:"});
        staticTexts.add({staticLabel:"Cell 2:"});
    }
    with(d.dialogColumns.add()){
        t = measurementEditboxes.add({editUnits:MeasurementUnits.POINTS, editValue:tv, minWidth:50});
        b = measurementEditboxes.add({editUnits:MeasurementUnits.POINTS, editValue:bv, minWidth:50});
    }
    if(d.show() == true){
        //get the edit values
        t = t.editValue;
        b = b.editValue;

        //update defaults.xml with the entered dialog values
        xml.values.top = t;
        xml.values.bottom = b;
        writeXML(f, xml.toXMLString());

        //run main script
        app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Dimensions');
        d.destroy();
	}
}

/**
* The main script 
*/
function main(){
    alert("Returned Dialog values:\r" + t + "\r" +b)
    $.writeln(xml)
    //returns the updated xml text
    
    //do something...
}

/**
* Write an XML file 
* @ param the file path 
* @ param the xml text 
* @ return void
*/
function writeXML(p,s){
    var file = new File(p);
    file.encoding = 'UTF-8';
    file.open('w');
    file.write(s);
    file.close();
}

/**
* Read an XML file 
* @ param the file path 
* @ returns an XML object
*/
function readXML(p) {
	var f = new File(p);
	f.open("r");  
	var t = f.read();  
	f.close();
	return XML(t); 
}

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2024 Aug 16, 2024

Copy link to clipboard

Copied

I agree entirely with @brian_p_dts. I stopped responding to dublove's queries a while ago. He or she uses this forum unashamedly as a free resource and shows very little appreciation.

 

@dublove -- You should do what other people do/have done: make a deal with someone privately who you can go to for help and the occasinal script. Pay them for their time. Such arrangements work very well. (I'm not offering.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 16, 2024 Aug 16, 2024

Copy link to clipboard

Copied

It's important to look at this issue in a dialectical way.
Asking questions is also a contribution. So, I am also a contributor.
Don't laugh, there is a point to this.

It's not like I'm lying to or hurting anyone. The questions I ask are open and perhaps needed by many others as well.
Thank you for your selflessness in helping us if you wish.

If you don't want to answer, you can remain silent.
If my question is useful to you, you can write the script and encrypt it him and put it on your site to sell.

Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2024 Aug 16, 2024

Copy link to clipboard

Copied

You could write the scripts, then encrypt them and sell them on your site.

 

Why don’t you do that?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 16, 2024 Aug 16, 2024

Copy link to clipboard

Copied

These are public ah.
How can I sell them?
If I can, that's another skill.

 

These are the problems that I have actually encountered in my work.
Not created. It is encountered and summarised.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

作为同胞,我觉得有点丢脸了,起码的礼貌都没有,谁还会帮这样的人?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

我哪一句没有礼貌?

你连提问的能力都没有,何来资格攻击邪恶别人?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

😂我甚至有能力解决你提出的问题,但我看了你在这个社区的行为,觉得不值得帮

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

LATEST

你觉得你有资格与我交流吗?更别说是同胞,建议你远离!

我除了问的问题多,我有什么问题?

 

你这是心有邪恶,灵魂不纯。

一个人一旦有恶念,本身就是一件邪恶和可怕的事情。

 

对不起大家,有人攻击我,我得还击。

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

Hi @dublove ,

if you want really ALL cells for ALL tables in a document with a specific width you could use this one line of ExtendScript (JavaScript) code:

 

app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().width = "20 mm";

 

If you want to address the cells of a specific column in all of your tables like all first column cells use this:

app.documents[0].stories.everyItem().tables.everyItem().columns[0].cells.everyItem().width = "20 mm";

 

Or if you want all cells of all last columns, independently how many columns a table has, than this code:

app.documents[0].stories.everyItem().tables.everyItem().columns[-1].cells.everyItem().width = "20 mm";

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

Well, because all cells in one column must be the same width, one could also write:

app.documents[0].stories.everyItem().tables.everyItem().columns.everyItem().width = "20 mm";

Why? Table columns also have a width property. With this in mind for all first table columns in your document:

app.documents[0].stories.everyItem().tables.everyItem().columns[0].width = "20 mm";

For all last columns:

app.documents[0].stories.everyItem().tables.everyItem().columns[-1].width = "20 mm";

Note:

columns[0] addresses the first column.

columns[1] addresses the second column.

columns[-1] addresses the last column.

columns[-2] addresses the one before the last column.

 

To make columns[n] work, you need at least ONE table in your document, that has n + 1 columns.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

I have used this script for some years to format tables to a consistent size (I'm not sure where it came from, sorry).

 

It only does a single table at a time, but it is still pretty quick to do a whole lot as it just requires the table to be selected and then the script run.

 

You set the column widths in the 'var myWidths = [60, 10, 10, 10];' line of the script so it remembers the last figures you entered.

 

var myDoc = app.activeDocument;
var myWidths = [60, 10, 10, 10];
for(var T=0; T < myDoc.textFrames.length; T++){
for(var i=0; i < myDoc.textFrames[T].tables.length; i++){
for(var j=0; j < myWidths.length; j++){
myDoc.textFrames[T].tables[i].columns[j].width = myWidths[j];
}
}
}
alert("Table width updated successfully...");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 15, 2024 Aug 15, 2024

Copy link to clipboard

Copied

This is nice.But it changed all.

How to target only the table where the current cursor is?

it would be great to be able to store multiple sets of values for easy selection.
The alert line is unnecessary.
Thank you very much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines