Copy link to clipboard
Copied
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.
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]],
});
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
...
Copy link to clipboard
Copied
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]],
});
Copy link to clipboard
Copied
@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
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Awesome!!! Loved it. Thanks so much.
I dont know what I would have done without great people like you! @Peter Kahrel @m1b
Copy link to clipboard
Copied
I agree! I get sooooo much help here! š