Skip to main content
eckerc87016678
Participant
April 1, 2025
Answered

Grundlinienraster

  • April 1, 2025
  • 4 replies
  • 542 views

Die Einstellung der Grundlinienrasters sollte über ein extra Fenster erfolgen, bei dem mittels Live Preview das Raster zu sehen ist. Außerdem sollte die erste Zeile des Grunlinienrasters auf die Versalhöhe des Grundtextes einstellbar sein. Die bisherige Einstellung über das Voreinstellungsfenster ist sehr mühsam.

Correct answer Laubender

Hallo @eckerc87016678 ,

es gibt ein Script von Roland Dreger, das ziemlich genau das macht, was Du Dir wünschst:

 

Grundlinienraster einrichten per Skript
Roland Dreger, 3. November 2018 • InDesign JavaScript

Das Script »setUpBaselineGrid.jsx« vereinfacht das Einrichten von Grundlinienraster und Satzspiegel in Adobe InDesign.


https://www.rolanddreger.net/de/9/grundlinienraster-einrichten-per-skript/#

 

Regards,
Uwe Laubender
( Adobe Community Expert )

4 replies

LaubenderCommunity ExpertCorrect answer
Community Expert
April 1, 2025

Hallo @eckerc87016678 ,

es gibt ein Script von Roland Dreger, das ziemlich genau das macht, was Du Dir wünschst:

 

Grundlinienraster einrichten per Skript
Roland Dreger, 3. November 2018 • InDesign JavaScript

Das Script »setUpBaselineGrid.jsx« vereinfacht das Einrichten von Grundlinienraster und Satzspiegel in Adobe InDesign.


https://www.rolanddreger.net/de/9/grundlinienraster-einrichten-per-skript/#

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Community Expert
April 2, 2025

Far better than the stage I was at in my attempt - this script is amazing 


Community Expert
April 2, 2025

Gonna post what I have - it's far simpler than the already available working script but as a lesson maybe I can share what I have and maybe it can be fixed 

 

So the Cap Height isn't working for me - but I can't figure out why. 

 

#target indesign
#targetengine "session"

$.writeln("--- Script Start ---");

// Function to safely get document vertical units info (More Robust)
function getDocumentVerticalUnits(doc) {
    var defaultUnitInfo = { type: MeasurementUnits.POINTS, name: "pt" };
    try {
        if (!doc || !doc.isValid || !doc.viewPreferences) {
             $.writeln("Warning: Invalid document or viewPreferences in getDocumentVerticalUnits. Falling back to points.");
             return defaultUnitInfo;
        }
        var unitType = doc.viewPreferences.verticalMeasurementUnits;
        var unitInfo = { type: unitType, name: "" };
        switch (unitType) {
            case MeasurementUnits.POINTS: unitInfo.name = "pt"; break;
            case MeasurementUnits.PICAS: unitInfo.name = "p"; break;
            case MeasurementUnits.INCHES: unitInfo.name = "in"; break;
            case MeasurementUnits.INCHES_DECIMAL: unitInfo.name = "in"; break;
            case MeasurementUnits.MILLIMETERS: unitInfo.name = "mm"; break;
            case MeasurementUnits.CENTIMETERS: unitInfo.name = "cm"; break;
            case MeasurementUnits.CICEROS: unitInfo.name = "c"; break;
            case MeasurementUnits.AGATES: unitInfo.name = "ag"; break;
            case MeasurementUnits.PIXELS: unitInfo.name = "px"; break;
            default: 
                unitInfo.name = "pt"; 
                unitInfo.type = MeasurementUnits.POINTS;
                $.writeln("Warning: Unknown MeasurementUnit encountered (" + unitType + "). Falling back to points.");
        }
         if (typeof unitInfo.name !== 'string' || unitInfo.name === "") {
             $.writeln("Warning: Failed to determine unit name. Falling back to points.");
             return defaultUnitInfo;
         }
        return unitInfo;
    } catch (e) {
        $.writeln("!!! ERROR in getDocumentVerticalUnits: " + e.message + ". Falling back to points.");
        return defaultUnitInfo;
    }
}

// Function to convert points to document units for display (More Robust)
function pointsToDocUnits(points, unitInfo) {
    try {
        if (typeof points !== 'number' || isNaN(points)) {
             $.writeln("Warning: Invalid 'points' value ("+ points +") received in pointsToDocUnits. Returning 0.");
             points = 0;
        }
         if (!unitInfo || typeof unitInfo.name !== 'string' || unitInfo.name === "") {
            $.writeln("Warning: Invalid 'unitInfo' received in pointsToDocUnits. Using points value directly.");
             return points;
         }
        var unitValue = UnitValue(points, "pt");
        return unitValue.as(unitInfo.name);
    } catch (e) {
         $.writeln("!!! ERROR converting points ("+ points +") to doc units ("+ (unitInfo ? unitInfo.name : 'N/A') +"): " + e.message + ". Returning original points value.");
         return points;
    }
}

// Function to convert document units input string to points
function docUnitsInputToPoints(inputString, unitInfo) {
    try {
        var unitValue = UnitValue(inputString);
        // Use unitInfo.name if input is just a number
        if (/^\d+(\.\d+)?$/.test(inputString)) {
             if(unitInfo && unitInfo.name){
                unitValue = UnitValue(parseFloat(inputString), unitInfo.name);
             } else {
                 // If no unitInfo, assume points if just a number
                 unitValue = UnitValue(parseFloat(inputString), "pt");
                 $.writeln("Warning: Assuming points for unitless input due to missing unitInfo.");
             }
        }
        return unitValue.as("pt");
    } catch (e) {
         $.writeln("!!! ERROR converting input string '"+ inputString +"' to points: " + e.message);
        return NaN;
    }
}


function createRealTimeBaselineGridAdjuster() {
    $.writeln("Entering createRealTimeBaselineGridAdjuster function...");

    if (app.documents.length === 0) {
        alert("Please open a document before running this script.");
        $.writeln("No document open. Alert shown. Exiting.");
        return;
    }
    $.writeln("Document found.");

    var doc = app.activeDocument;
    var gridPrefs = doc.gridPreferences;
    $.writeln("Accessing document preferences...");
    var docUnitsInfo = getDocumentVerticalUnits(doc);
    $.writeln("Got document units: " + (docUnitsInfo ? docUnitsInfo.name : 'FAILED TO GET UNITS'));
    var updateFromCheckbox = false;
    var pal, incrementGroup, baselineInput, offsetGroup, firstLineInput;
    var capHeightGroup, capHeightCheckbox, capHeightInfo, closeButton;

    try {
        $.writeln("Attempting to create palette window...");
        pal = new Window("palette", "Live Baseline Grid");
        if (!pal) throw new Error("new Window() failed to return an object.");
        $.writeln(" -> Palette created.");
        pal.orientation = "column";
        pal.alignChildren = "fill";
        pal.spacing = 10;
        pal.margins = 15;
        $.writeln(" -> Palette properties set.");

        // --- Baseline Increment ---
        $.writeln("Adding incrementGroup...");
        incrementGroup = pal.add("group");
        if (!incrementGroup) throw new Error("Failed to add incrementGroup.");
        incrementGroup.orientation = "row";
        incrementGroup.alignChildren = "left";
        incrementGroup.add("statictext", undefined, "Increment (" + docUnitsInfo.name + "):");
        var initialIncrementValue = pointsToDocUnits(gridPrefs.baselineDivision, docUnitsInfo);
        $.writeln(" -> initialIncrementValue = " + initialIncrementValue);
        baselineInput = incrementGroup.add("edittext", undefined, initialIncrementValue.toFixed(3));
        if (!baselineInput) throw new Error("Failed to create baselineInput.");
        baselineInput.characters = 8;
        baselineInput.active = true;

        // --- First Baseline Offset ---
        $.writeln("Adding offsetGroup...");
        offsetGroup = pal.add("group");
        if (!offsetGroup) throw new Error("Failed to add offsetGroup.");
        offsetGroup.orientation = "row";
        offsetGroup.alignChildren = "left";
        offsetGroup.add("statictext", undefined, "Start Offset (" + docUnitsInfo.name + "):");
        var initialOffsetValue = pointsToDocUnits(gridPrefs.baselineStart, docUnitsInfo);
        $.writeln(" -> initialOffsetValue = " + initialOffsetValue);
        firstLineInput = offsetGroup.add("edittext", undefined, initialOffsetValue.toFixed(3));
        if (!firstLineInput) throw new Error("Failed to create firstLineInput.");
        firstLineInput.characters = 8;

        // --- Align to Cap Height ---
        $.writeln("Adding capHeightGroup...");
        capHeightGroup = pal.add("group");
        if (!capHeightGroup) throw new Error("Failed to add capHeightGroup.");
        capHeightGroup.orientation = "column";
        capHeightGroup.alignChildren = "left";
        capHeightCheckbox = capHeightGroup.add("checkbox", undefined, "Align First Line Offset to Cap Height");
        if (!capHeightCheckbox) throw new Error("Failed to create capHeightCheckbox.");
        capHeightCheckbox.helpTip = "Uses Document Text Defaults Font/Size";
        capHeightInfo = capHeightGroup.add("statictext", undefined, "(Uses doc defaults: Font/Size)", { multiline: false, truncate: 'end'});
        if (!capHeightInfo) throw new Error("Failed to create capHeightInfo.");
        capHeightInfo.characters = 30;
        capHeightInfo.enabled = false;

        // --- Update Function ---
        function updateGridSettings(sourceElement) {
            if (updateFromCheckbox) return;
            try {
                var currentIncrementPt = gridPrefs.baselineDivision;
                var currentStartPt = gridPrefs.baselineStart;

                // Apply Increment
                if (sourceElement === baselineInput || !sourceElement) {
                    var newIncrementRaw = baselineInput.text;
                    var newIncrementPt = docUnitsInputToPoints(newIncrementRaw, docUnitsInfo);
                    if (!isNaN(newIncrementPt) && newIncrementPt > 0 && Math.abs(newIncrementPt - currentIncrementPt) > 0.001) {
                        $.writeln("Updating baselineDivision from " + currentIncrementPt + "pt to " + newIncrementPt + "pt");
                        gridPrefs.baselineDivision = newIncrementPt;
                    } else if (isNaN(newIncrementPt)) {
                        $.writeln("Invalid increment input ignored: " + newIncrementRaw);
                    }
                }
                // Apply Start Offset (if checkbox is off)
                if ((sourceElement === firstLineInput || !sourceElement) && !capHeightCheckbox.value) {
                    var newStartRaw = firstLineInput.text;
                    var newStartPt = docUnitsInputToPoints(newStartRaw, docUnitsInfo);
                    if (!isNaN(newStartPt) && newStartPt >= 0 && Math.abs(newStartPt - currentStartPt) > 0.001) {
                        $.writeln("Updating baselineStart from " + currentStartPt + "pt to " + newStartPt + "pt");
                        gridPrefs.baselineStart = newStartPt;
                    } else if (isNaN(newStartPt)) {
                        $.writeln("Invalid start offset input ignored: " + newStartRaw);
                    }
                }
            } catch (e) {
                $.writeln("!!! ERROR in updateGridSettings: " + e.message);
            }
        }
        $.writeln(" -> Update function defined.");

        // Attach event listeners
        baselineInput.onChange = function() { $.writeln("baselineInput onChange triggered."); updateGridSettings(this); };
        firstLineInput.onChange = function() { $.writeln("firstLineInput onChange triggered."); updateGridSettings(this); };

        // Cap Height Checkbox Event
        capHeightCheckbox.onClick = function() {
            $.writeln("capHeightCheckbox onClick triggered. Value: " + this.value);
            if (this.value) {
                try {
                    var mainFont, mainSize;
                    if (doc.textDefaults.appliedFont && typeof doc.textDefaults.appliedFont !== 'string' && doc.textDefaults.pointSize > 0) {
                        mainFont = doc.textDefaults.appliedFont;
                        mainSize = doc.textDefaults.pointSize;
                        $.writeln("Using doc textDefaults: " + mainFont.name + ", " + mainSize + "pt");
                    } else {
                        $.writeln("Doc textDefaults not set or invalid.");
                        alert("Document Text Defaults (Font/Size) are not set or invalid. Cannot calculate Cap Height.");
                        this.value = false;
                        firstLineInput.enabled = true;
                        capHeightInfo.enabled = false;
                        return;
                    }
                    if (typeof mainFont === 'string' || !mainFont.isValid) { 
                        throw new Error("Default font is not valid or missing."); 
                    }
                    var capHeightPt = mainFont.capitalHeight * (mainSize / 1000);
                    $.writeln("Calculated capHeightPt: " + capHeightPt);
                    if (isNaN(capHeightPt) || capHeightPt < 0) { throw new Error("Calculated cap height is invalid."); }
                    updateFromCheckbox = true;
                    $.writeln("Updating baselineStart to capHeight: " + capHeightPt + "pt");
                    gridPrefs.baselineStart = capHeightPt;
                    var capHeightDocUnits = pointsToDocUnits(capHeightPt, docUnitsInfo);
                    $.writeln(" -> capHeight in doc units: " + capHeightDocUnits);
                    firstLineInput.text = capHeightDocUnits.toFixed(3);
                    firstLineInput.enabled = false;
                    capHeightInfo.text = "(Uses: " + mainFont.name + " / " + mainSize + "pt)";
                    capHeightInfo.enabled = true;
                    updateFromCheckbox = false;
                    $.writeln("Cap height applied successfully.");
                } catch (e) {
                    $.writeln("!!! ERROR applying cap height: " + e.message);
                    alert("Could not calculate or apply cap height:\n" + e.message);
                    this.value = false;
                    firstLineInput.enabled = true;
                    capHeightInfo.enabled = false;
                    capHeightInfo.text = "(Uses doc defaults: Font/Size)";
                    updateFromCheckbox = false;
                }
            } else {
                $.writeln("Cap height checkbox unchecked. Enabling manual input.");
                firstLineInput.enabled = true;
                capHeightInfo.enabled = false;
                capHeightInfo.text = "(Uses doc defaults: Font/Size)";
            }
        };

        // Initial state check for checkbox
        if (capHeightCheckbox.value) {
            $.writeln("Triggering initial cap height check...");
            capHeightCheckbox.notify("onClick");
        } else {
            $.writeln("Initial cap height checkbox is not checked.");
        }

        // --- Close Button ---
        $.writeln("Adding Close button...");
        closeButton = pal.add("button", undefined, "Close");
        if (!closeButton) throw new Error("Failed to create Close button.");
        closeButton.onClick = function() { $.writeln("Close button clicked."); pal.close(); };

        // --- Show Palette ---
        $.writeln("Centering palette...");
        pal.center();
        $.writeln("Calling pal.show()...");
        pal.show();
        $.writeln("Palette should now be visible and persistent.");
    } catch (e) {
        $.writeln("\n!!! ERROR during palette creation: " + e.message + " (Line: " + e.line + ")");
        alert("Error creating script window: " + e.message + "\nCheck ESTK Console for details.");
    }
    $.writeln("Exiting createRealTimeBaselineGridAdjuster function.");
}

// --- Run the main function DIRECTLY ---
try {
     $.writeln("Calling createRealTimeBaselineGridAdjuster...");
     createRealTimeBaselineGridAdjuster();
     $.writeln("createRealTimeBaselineGridAdjuster finished.");
} catch(e) {
    $.writeln("!!! FATAL ERROR: " + e.message + " (Line: " + e.line + ")");
    alert("Fatal script error:\n" + e.message);
}

$.writeln("--- Script End ---");

 

 

 

Robert at ID-Tasker
Legend
April 1, 2025

@eckerc87016678

 

But you should rather know / calculate all the values in advance - not to play with them - based on the page size, margins, point size of the text, etc.

 

leo.r
Community Expert
Community Expert
April 1, 2025
quote

The previous setting via the preferences window is very tedious.

By @eckerc87016678

 

I agree that adjusting it through the Preferences window isn't exactly convenient, especially since the Preferences window doesn't remember the last selected preference group and you have to reselect it again every time.

 

You can submit feature requests here:

https://indesign.uservoice.com/forums/601021-adobe-indesign-feature-requests

 

...and also upvote my old request to remember the last Preferences choice, which didn't gather much traction: 

https://indesign.uservoice.com/forums/601021-adobe-indesign-feature-requests/suggestions/47188808-remember-last-selected-section-in-preferences

 

Willi Adelberger
Community Expert
Community Expert
April 1, 2025

Du kannst den Grundlinienraster auch über Objektformate einstellen und da kannst du wählen, ob es auf Großbuchstabenhöhe (H-Höe) oder anderen Schrifteigenschaften bezogen wird. Das mag für dich einfacher sein.

eckerc87016678
Participant
April 1, 2025

Das gilt aber nur für die Textrahmenoptionen und nicht global für das gesamte Dokument.

Freundliche Grüße

Christian Ecker
Studiendirektor
Fachbetreuer Druck/Medien
[Contact information removed]