Skip to main content
Participant
March 25, 2025
Answered

Tabellen-Zellen Mindesthöhe in Formatvorlage

  • March 25, 2025
  • 2 replies
  • 398 views

Ich muss global in einem Dokument die Zellenhöhe aller Tabellen auf eine Mindesthöhe setzen, ist aktuell bei einem festen Wert und verursacht Übersatztext. Diese Option ist leider weder im Tabellenformat noch im Zellenformat einzustellen, es geht nur, wenn man eine einzelne Tabelle erstellt oder bearbeitet. Gibt es hier ein Scrpit o.ä., was die Mindesthöhe auch in die Formatvorlagen schreiben kann? Danke und VG Anna

Correct answer Eugene Tyson

Yeh I figured it can be better than what I came up. I often can't get the script to do what I want so find another approach. I think I got an error trying it your way, and that's why I tried a different route. I see know how that works, thanks a lot. 


As you can gather I'm taking bits and bobs and piecing them together. 

I always forget the undo part when doing proof of concept scripts.  


So my next attempt - wondering if this is better or just stick to what you've done - as I do try - I often don't take all issues into account - what do you think @m1b 

I'll save the wrapundo function separately as a must add for all scripts - it's so handy.

function setMinRowHeightNested() {
    // Set measurement unit to points for consistency
    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
    var minHeight = 10;
    var doc = app.activeDocument;
    
    // Loop through each story in the document
    for (var s = 0; s < doc.stories.length; s++) {
        var story = doc.stories[s];
        
        // Loop through each table in the current story
        for (var t = 0; t < story.tables.length; t++) {
            var table = story.tables[t];
            
            // Loop through each row in the table
            for (var r = 0; r < table.rows.length; r++) {
                var row = table.rows[r];
                row.autoGrow = true;
                row.minimumHeight = minHeight;
            }
        }
    }
}

// Wrap the whole script in a doScript call for undo support
app.doScript(setMinRowHeightNested, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Set Min Row Height Nested");

 

2 replies

Robert at ID-Tasker
Legend
March 26, 2025

@Anna38893690gaxg 

 

Unfortunately, Cell and Table Styles don't have the "height" property as part of their definition.

 

But you can use this simple script to reset all tables in your document:

app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().autoGrow = false;
app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().height = 2;
app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().autoGrow = true;

The extra benefit - it will first set the height to EACTLY so your Tables will look like this - if they are empty:

 

If it's not what you're looking for - then please comment first line:

 

And, just in case:

https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post/

 

m1b
Community Expert
Community Expert
March 26, 2025

Yes @Robert at ID-Tasker that is a handy trick. Setting the minimumHeight will give the same effect, I think.

Community Expert
March 25, 2025

Hey there

 

You can it this way
Adjut the first line numbers - it should adjust to whatever units you're using. If it doesn't let us know.

 

var minHeight = 10;
var myDoc = app.activeDocument;

for (var i = 0; i < myDoc.stories.length; i++) {
    var myStory = myDoc.stories[i];
    for (var j = 0; j < myStory.tables.length; j++) {
        var myTable = myStory.tables[j];
        for (var r = 0; r < myTable.rows.length; r++) {
            var myRow = myTable.rows[r];
            if (myRow.height < minHeight || myRow.rowType === RowTypes.BODY_ROW) {
                myRow.height = minHeight;
                myRow.autoGrow = true;
            }
        }
    }
}

 

https://creativepro.com/sizing-tables-with-script/

https://creativepro.com/tackling-tables-through-scripting/

 

 

m1b
Community Expert
Community Expert
March 26, 2025

Hey @Eugene Tyson that'll work well, but a couple of notes:

1. you could set the row's minimumHeight property without worrying about setting the height because you have autoGrow turned on.

2. if you do (1) you can remove the myRow.height < minHeight predicate, which would be better because as it is you aren't setting autoGrow on every row.

3. It really is worth wrapping the whole script in a doScript call, because it means that you can undo the whole thing.

4. if you want to simplify your code a bit you can collect all the rows and loop just once over them.

 

Put those points all together, you get something like this:

function main() {

    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

    const MIN_HEIGHT = 10;

    var myDoc = app.activeDocument;
    var rows = myDoc.stories.everyItem().tables.everyItem().rows;

    if (!rows.length)
        // no rows found
        return;

    rows = rows.everyItem().getElements();

    // go backwards in case the document reflows
    for (var i = rows.length - 1; i >= 0; i--) {

        rows[i].properties = {
            autoGrow: true,
            minimumHeight: MIN_HEIGHT,
        };

    }

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Minimum Row Height');

 

Again, just for learning. Your current script does the job pretty well already. 🙂

- Mark

Community Expert
March 26, 2025

Yeh I figured it can be better than what I came up. I often can't get the script to do what I want so find another approach. I think I got an error trying it your way, and that's why I tried a different route. I see know how that works, thanks a lot. 


As you can gather I'm taking bits and bobs and piecing them together. 

I always forget the undo part when doing proof of concept scripts.