Skip to main content
Known Participant
January 16, 2025
Question

Shortcut for break frame

  • January 16, 2025
  • 14 replies
  • 1062 views

Hello 

I am using indesign cs6.   i want to break a frame as one word in one line.  For more understand i am upload two image. one pic for many sentence which want to break. second image for output means What I want. can you provide any script or any shortcut command for it.

14 replies

Community Expert
January 16, 2025

 

Well this does it but if you need anything extra just ask

Hope it helps

 

if (app.documents.length > 0 && app.selection.length > 0 && app.selection[0] instanceof TextFrame) {
    var originalFrame = app.selection[0];
    var paragraphs = originalFrame.parentStory.paragraphs;

    // Get the original frame's position and size
    var frameBounds = originalFrame.geometricBounds; // [top, left, bottom, right]
    var x = frameBounds[1];
    var y = frameBounds[0];
    var width = frameBounds[3] - frameBounds[1];

    // Iterate over paragraphs and create new text frames
    for (var i = 0; i < paragraphs.length; i++) {
        var paragraphText = paragraphs[i].contents;

        // Create a new text frame for each paragraph
        var newFrame = originalFrame.parentPage.textFrames.add();
        newFrame.geometricBounds = [y, x, y + 20, x + width]; // Adjust height (20) as needed
        newFrame.contents = paragraphText;

        // Adjust position for the next frame
        y += 25; // Spacing between frames (adjust as needed)
    }

    // Optionally remove the original frame
    originalFrame.remove();

    alert("Paragraphs have been split into separate text frames.");
} else {
    alert("Please select a single text frame.");
}
Robert at ID-Tasker
Legend
January 16, 2025

@Eugene Tyson

 

You can't just copy contents - just in case there would be different Styles applied / local formatting. 

 

And instead of creating a new TextFrame - duplicate original one and change its bounds.

 

Community Expert
January 16, 2025

 

Ok - thanks for the feedback - included a 1 step undo too.

 

What do you think? 

 

if (app.documents.length > 0 && app.selection.length > 0 && app.selection[0] instanceof TextFrame) {
    app.doScript(function () {
        var originalFrame = app.selection[0];
        var paragraphs = originalFrame.parentStory.paragraphs;

        // Get original frame bounds
        var frameBounds = originalFrame.geometricBounds; // [top, left, bottom, right]
        var x = frameBounds[1];
        var y = frameBounds[0];
        var width = frameBounds[3] - frameBounds[1];

        // Disable redraw for better performance
        app.scriptPreferences.enableRedraw = false;
        var parentPage = originalFrame.parentPage;

        // Iterate over paragraphs and create new frames
        for (var i = 0; i < paragraphs.length; i++) {
            var paragraph = paragraphs[i];

            // Duplicate the original text frame to preserve formatting
            var newFrame = originalFrame.duplicate();
            newFrame.geometricBounds = [y, x, y + 30, x + width]; // Adjust height (30) if needed

            // Keep only the current paragraph and remove other content
            newFrame.parentStory.texts[0].contents = paragraph.contents;

            // Adjust position for the next frame
            y += 35; // Adjust spacing as needed
        }

        // Optionally remove the original frame
        originalFrame.remove();

        // Re-enable redraw
        app.scriptPreferences.enableRedraw = true;

        alert("Paragraphs have been split into separate text frames.");
    }, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Split Paragraphs into Frames");
} else {
    alert("Please select a single text frame.");
}