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

script for adjusting table and cell properties

Participant ,
Jan 01, 2017 Jan 01, 2017

Copy link to clipboard

Copied

I have many tables in my file, is there any script which can help me to apply below properties ignore font and its font family,

my procedure will be i will select the whole single table and i will click the script and below properties will be applied...

font size 7 and leading 8

and cell properties

and row hieght

Thanks in advance!!!

Views

4.1K

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 1 Correct answer

Guru , Jan 02, 2017 Jan 02, 2017

You wrote: "font size 7 and leading 8". So I thought you wanted to apply only these values.

Anyway, in JavaScript it is quite easy to make modifications by intuition -- even for those who are unfamiliar with coding.

Here's another version. You can select either the whole table, or one or more cells

Also, in this version you can Undo-Redo the whole script.

02-01-2017 18-06-20.png

var scriptName = "Table",

doc;

app.doScript(PreCheck, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "\"" + scriptName + "\" script"

...

Votes

Translate

Translate
Guru ,
Jan 01, 2017 Jan 01, 2017

Copy link to clipboard

Copied

Let's try this script. Place the cursor into the table an run it.

var scriptName = "Table",

doc;

PreCheck();

//===================================== FUNCTIONS ======================================

function Main() {

    var table = CatchTable();

   

    table.cells.everyItem().texts[0].pointSize = "7 pt";

    table.cells.everyItem().texts[0].leading = "8 pt";

    table.cells.everyItem().leftInset = table.cells.everyItem().rightInset = "1 mm";

    table.cells.everyItem().topInset = table.cells.everyItem().bottomInset = "0.5 mm";

    table.cells.everyItem().verticalJustification = VerticalJustification.CENTER_ALIGN;

    table.cells.everyItem().autoGrow = true;

    table.cells.everyItem().minimumHeight = "3.75 mm";

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function CatchTable() {

    if (app.selection.length > 0) {

        if (app.selection[0].parent.constructor.name == "Table") {

            return app.selection[0].parent;

        }

        else if (app.selection[0].parent.parent.constructor.name == "Table") {

            return app.selection[0].parent.parent;

        }

        else {

            ErrorExit("Place the cursor into the table.", true);

        }

    } else {

        ErrorExit("Place the cursor into the table.", true);

    }

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function PreCheck() {

    if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);

    doc = app.activeDocument;

    if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);

    if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);

    Main();

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function ErrorExit(error, icon) {

    alert(error, scriptName, icon);

    exit();

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

Hope it helps!

— Kas

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
Participant ,
Jan 01, 2017 Jan 01, 2017

Copy link to clipboard

Copied

Thank u very much!!! it works u help me lot with this script, there is only one problem, which i have mentioned below, can u please solve this by modifying the same script...

Thanks in Advance

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
Participant ,
Jan 01, 2017 Jan 01, 2017

Copy link to clipboard

Copied

I have modified the script to adjust kerning and tracking value, and it works but it was not possible without ur script!!! thanks again...

modified script

    table.cells.everyItem().texts[0].pointSize = "7 pt"; 

    table.cells.everyItem().texts[0].leading = "8 pt"; 

    table.cells.everyItem().texts[0].tracking = 0; 

    table.cells.everyItem().texts[0].kerningValue = 0;

    table.cells.everyItem().leftInset = table.cells.everyItem().rightInset = "1 mm"; 

    table.cells.everyItem().topInset = table.cells.everyItem().bottomInset = "0.5 mm"; 

    table.cells.everyItem().verticalJustification = VerticalJustification.CENTER_ALIGN; 

    table.cells.everyItem().autoGrow = true; 

    table.cells.everyItem().minimumHeight = "3.75 mm"; 

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
Participant ,
Jan 02, 2017 Jan 02, 2017

Copy link to clipboard

Copied

I got 1 problem, can I apply this script to selected cells, because there is one row which I don't want these properties to be applied it as to be left as it is ...

Thanks in advance

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
Guru ,
Jan 02, 2017 Jan 02, 2017

Copy link to clipboard

Copied

You wrote: "font size 7 and leading 8". So I thought you wanted to apply only these values.

Anyway, in JavaScript it is quite easy to make modifications by intuition -- even for those who are unfamiliar with coding.

Here's another version. You can select either the whole table, or one or more cells

Also, in this version you can Undo-Redo the whole script.

02-01-2017 18-06-20.png

var scriptName = "Table",

doc;

app.doScript(PreCheck, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "\"" + scriptName + "\" script");

//===================================== FUNCTIONS ======================================

function Main() {

    if (app.selection[0].constructor.name == "Table") {

        var cells = app.selection[0].cells.everyItem().getElements();

        for (var i = 0; i < cells.length; i++) {

            ProcessCell(cells);

        }

    }

    else {

        ProcessCell(app.selection[0]);

    }

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function ProcessCell(cell) {

    cell.texts[0].pointSize = "7 pt";

    cell.texts[0].leading = "8 pt";

    cell.texts[0].tracking = 0;

    cell.texts[0].kerningValue = 0;

    cell.leftInset = cell.rightInset = "1 mm";

    cell.topInset = cell.bottomInset = "0.5 mm";

    cell.verticalJustification = VerticalJustification.CENTER_ALIGN;

    cell.autoGrow = true;

    cell.minimumHeight = "3.75 mm";   

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function PreCheck() {

    if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);

    doc = app.activeDocument;

    if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);

    if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);

    if (app.selection.length == 0) ErrorExit("Nothing is selected, Select some cells and try again.", true);

    if (app.selection[0].constructor.name != "Cell" && app.selection[0].constructor.name != "Table") ErrorExit("Select a table, or one or more cells and try again.", true);

    Main();

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function ErrorExit(error, icon) {

    alert(error, scriptName, icon);

    exit();

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

— Kas

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
Participant ,
Mar 08, 2017 Mar 08, 2017

Copy link to clipboard

Copied

hello, thanks for your script, but when I select complete table i.e all rows and columns the all above properties get applied but when I select particular 5 cells or a single row of 6 cells the properties get applied to only first cell ( font size and line spacing do not get change after second cell )

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
Guru ,
Mar 08, 2017 Mar 08, 2017

Copy link to clipboard

Copied

Hi there,

The script assumes that only a table should be selected. I don't remember why I did it since it was a couple of months ago.

Modify the line #8 like so:

if (app.selection[0].constructor.name == "Table" || app.selection[0].constructor.name == "Cell") {

This way it will work with selected cells as well.

— Kas

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
Participant ,
Mar 08, 2017 Mar 08, 2017

Copy link to clipboard

Copied

thanks it woks,

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
Participant ,
Mar 09, 2017 Mar 09, 2017

Copy link to clipboard

Copied

LATEST

Untitled-1.jpg

can you please add more commands in scripts to keep value as per above highlighted...
ie vertical and horizontal scale as "100", baseline shift and character rotation as "0"

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 ,
Jan 02, 2017 Jan 02, 2017

Copy link to clipboard

Copied

I would do it with Table and Cell Styles, not with a 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
Participant ,
Jan 02, 2017 Jan 02, 2017

Copy link to clipboard

Copied

I cant create additional styles in my file because it is against policy of my project

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