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

Script to split and merge textboxes in InDesign

Enthusiast ,
Apr 13, 2023 Apr 13, 2023

Hello all. I have multiple text boxes threaded (screeshot attached). When the text in frame is too much to handle, I select 2/3 frames and then merge them. This part is easy using pathfinder. BUT issue is splitting them.
I just want to select the text frame and just run the script to split text frame to exact halves or into 3 parts. How do I achieve this using script ? Or is there a better method?
Currently I am creating a new text box and then re-threading them to achieve what I want but its too cumbersome.
Any help would be appreciated. Thanks.

TOPICS
How to , Scripting
2.3K
Translate
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 2 Correct answers

Community Expert , Apr 13, 2023 Apr 13, 2023

Use the frame's geometric bounds. To split the selected frame into three parts:

frame = app.selection[0];
gb = frame.geometricBounds;
w = (gb[3]-gb[1])/3;

// Resize the original frame

frame.geometricBounds = [gb[0], gb[1], gb[2], gb[1]+w];

// Then add two frames:

frame.parentPage.textFrames.add ({
  geometricBounds: [gb[0], gb[1]+w, gb[2], gb[1]+(w*2)],
});

frame.parentPage.textFrames.add ({
  geometricBounds: [gb[0], gb[1]+(w*2), gb[2], gb[3]],
});
Translate
Community Expert , Apr 13, 2023 Apr 13, 2023

Just to warm up my brain a little, here's a version of Peter's script converted into a function:

function main() {
    var frames = splitFrame(app.selection[0], prompt('Split into how many frames?', '2'));
}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Split Frame');


/**
 * Splits a text frame by dividing the width.
 * @Param {TextFrame} frame - an Indesign TextFrame.
 * @Param {Number} frameCount - the desired number of frames.
 * @Returns {Array<TextFra
...
Translate
Community Expert ,
Apr 13, 2023 Apr 13, 2023

Use the frame's geometric bounds. To split the selected frame into three parts:

frame = app.selection[0];
gb = frame.geometricBounds;
w = (gb[3]-gb[1])/3;

// Resize the original frame

frame.geometricBounds = [gb[0], gb[1], gb[2], gb[1]+w];

// Then add two frames:

frame.parentPage.textFrames.add ({
  geometricBounds: [gb[0], gb[1]+w, gb[2], gb[1]+(w*2)],
});

frame.parentPage.textFrames.add ({
  geometricBounds: [gb[0], gb[1]+(w*2), gb[2], gb[3]],
});
Translate
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
Enthusiast ,
Apr 13, 2023 Apr 13, 2023

@Peter Kahrel Thanks for the quick reply.

The script works fine but after splitting it is not going to the "Before" position (screenshot attached).

Or I am not selecting the right frames ?

 

Regards

 

Translate
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
Enthusiast ,
Apr 13, 2023 Apr 13, 2023

@Peter Kahrel Ok. I got it.

 

I changed this line from:

w = (gb[3]-gb[1])/3;

to

w = (gb[3]-gb[1])/2;

And it worked.

 

Thanks a lot. You have been a saviour.

Translate
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 ,
Apr 13, 2023 Apr 13, 2023

Just to warm up my brain a little, here's a version of Peter's script converted into a function:

function main() {
    var frames = splitFrame(app.selection[0], prompt('Split into how many frames?', '2'));
}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Split Frame');


/**
 * Splits a text frame by dividing the width.
 * @Param {TextFrame} frame - an Indesign TextFrame.
 * @Param {Number} frameCount - the desired number of frames.
 * @Returns {Array<TextFrame>} - the split frames.
 */
function splitFrame(frame, frameCount) {

    frameCount = Number(frameCount);

    if (
        isNaN(frameCount) || frameCount < 2
        || frame == undefined || !frame.isValid
    )
        return;

    var gb = frame.geometricBounds,
        w = (gb[3] - gb[1]) / frameCount,
        tf = frame,
        frames = [tf];

    tf.geometricBounds = [gb[0], gb[1], gb[2], gb[1] + w];

    for (var i = 1; i < frameCount; i++) {
        frames.push(
            tf = frame.parentPage.textFrames.add({
                geometricBounds: [gb[0], gb[1] + (w * i), gb[2], gb[1] + (w * (i + 1))],
                previousTextFrame: tf
            })
        );
    }

    return frames;

};

- Mark 

Translate
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
Enthusiast ,
Apr 13, 2023 Apr 13, 2023

Awesome!!! Loved it. Thanks so much.

I dont know what I would have done without great people like you! @Peter Kahrel @m1b 

 

Translate
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 ,
Apr 14, 2023 Apr 14, 2023
LATEST

I agree! I get sooooo much help here! 🙂

Translate
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