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

Shortcut for break frame

New Here ,
Jan 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

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.

TOPICS
EPUB , Experiment , How to , Print , Scripting

Views

283

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 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

 

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.");
}

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 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

@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.

 

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 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

 

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.");
}

 

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 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

You misunderstod my comment.

 

When you copy .contents - you are copying ONLY text part of the Text object - without the applied formatting.

 

You either need to move() paragraph - iterating backward the original collection of Paragraphs - or copy&paste whole Paragraph.

 

And why do you "modify" width of the new TextFrame?

 

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 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

Those Two steps - won't give you what I've suggested:

 

            // Duplicate the original text frame to preserve formatting
            var newFrame = originalFrame.duplicate();

 

 

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

 

First one - will preserve "graphical" formatting - what I've suggested "between the lines".

 

Second - will still make text look wrong - if there are multiple Styles / local formatting.

 

You are just replacing contents of the whole TextFrame - with contents of the single Paragraph.

 

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 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

I hope it will work:

 

        for (var i = paragraphs.length-1; i >= 0; i--) 
        {
            // Duplicate the original text frame
            var newFrame = originalFrame.duplicate();
            newFrame.contents = "";
            paragraphs[i].move(LocationOptions.AT_BEGINNING,newFrame.texts[0]);

            newFrame.geometricBounds[0] = newFrame.geometricBounds[0]+y;
            newFrame.geometricBounds[2] = newFrame.geometricBounds[0]+y+30;

            //[y, x, y + 30, x + width]; // Adjust height (30) if needed

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

 

 

 

Untested, but if there are any errors - I'm sure you'll be able to fix them. 

 

It's just to show you what I mean.

 

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 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

quote

I hope it will work:

 

 

        for (var i = paragraphs.length-1; i >= 0; i--) 
        {
            // Duplicate the original text frame
            var newFrame = originalFrame.duplicate();
            newFrame.contents = "";
            paragraphs[i].move(LocationOptions.AT_BEGINNING,newFrame.texts[0]);

            newFrame.geometricBounds(0) = newFrame.geometricBounds(0)+y;
            newFrame.geometricBounds(2) = newFrame.geometricBounds(0)+y+30;

            //[y, x, y + 30, x + width]; // Adjust height (30) if needed

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

 

 

Untested, but if there are any errors - I'm sure you'll be able to fix them. 

 

It's just to show you what I mean.

 


By @Robert at ID-Tasker

 

That's not working for me

I had a look again - 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 the frame's geometry
        var frameBounds = originalFrame.geometricBounds; // [top, left, bottom, right]
        var x = frameBounds[1];
        var y = frameBounds[0];
        var width = frameBounds[3] - frameBounds[1];
        var height = 30; // Set height for each new frame
        var spacing = 5; // Space between frames

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

        // Loop through paragraphs and create frames
        for (var i = 0; i < paragraphs.length; i++) {
            originalFrame.parentPage.textFrames.add({
                geometricBounds: [y + (i * (height + spacing)), x, y + (i * (height + spacing)) + height, x + width],
                contents: paragraphs[i].contents
            });
        }

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

        // Re-enable redraw
        app.scriptPreferences.enableRedraw = true;
    }, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Split Paragraphs into Frames");
} else {
    alert("Please select a single text frame.");
}

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 17, 2025 Jan 17, 2025

Copy link to clipboard

Copied

@Eugene Tyson

 

What's not working in my code? What errors do you receive? 

 

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 17, 2025 Jan 17, 2025

Copy link to clipboard

Copied

quote

@Eugene Tyson

 

What's not working in my code? What errors do you receive? 

 


By @Robert at ID-Tasker

Can't remember the error. Sorry

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 17, 2025 Jan 17, 2025

Copy link to clipboard

Copied

LATEST

@Eugene Tyson

 

Right, It should be geometricBounds[] - not geometricBounds() - a reference to elements of the array. 

 

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 ,
Jan 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

@Eugene Tyson  Thank You sir for help me.  I am change little bit in your code then is working sir. Thank You sir

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 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

Hi Peeyush  can you let us know which code worked for you - what you changed and post the working code that you changed?

 

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 ,
Jan 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

I just noticed:

 

    var paragraphs = originalFrame.parentStory.paragraphs;

 

this might be a problem - if parentStory has more textContainers than currently selected TextFrame...

 

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 16, 2025 Jan 16, 2025

Copy link to clipboard

Copied

Could be. Let's wait for the op the get back on specific requirements

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