Single Multi Column text frame to individual separate text frames - Nearly working - Please help
Hello All,
I have the bulk of a script which takes a single frame of which has multi columns to split each of the columns into spearate, but threaded boxes retaining the same gutter etc
the only issue that the script repeats the text an eqaual amount of times as there are columns
as the script duplicates the single frame the same amount of times as there are columns and also then once done drops the text frame to only have one column.
Below is the code
Also this can be undone in one go to which I saw another online which was much longer code and couldnt be undone in one go
Any help or advice would be great
Best
Smyth
// Check if an InDesign document is open
if (app.documents.length > 0) {
var doc = app.activeDocument;
// Check if a text frame is selected
if (doc.selection.length === 1 && doc.selection[0] instanceof TextFrame) {
var selectedTextFrame = doc.selection[0];
app.doScript(function () {
// Get the linked story of the text frame
var story = selectedTextFrame.parentStory;
// Check if the text frame has multiple columns
if (selectedTextFrame.textColumns.length > 1) {
var columns = selectedTextFrame.textColumns;
var gutter = selectedTextFrame.textFramePreferences.textColumnGutter;
var columnWidth = (selectedTextFrame.geometricBounds[3] - selectedTextFrame.geometricBounds[1] - (gutter * (columns.length - 1))) / columns.length;
// Create an array to store the duplicated frames
var duplicatedFrames = [];
for (var i = 0; i < columns.length; i++) {
var newX1 = selectedTextFrame.geometricBounds[1] + (columnWidth + gutter) * i;
var newX2 = newX1 + columnWidth;
// Duplicate the selectedTextFrame
var newFrame = selectedTextFrame.duplicate();
newFrame.geometricBounds = [selectedTextFrame.geometricBounds[0], newX1, selectedTextFrame.geometricBounds[2], newX2];
// Set column count to 1 for the duplicated frame
newFrame.textFramePreferences.textColumnCount = 1;
// Add the duplicated frame to the array
duplicatedFrames.push(newFrame);
}
// Remove the original multi-column text frame
selectedTextFrame.remove();
// Thread the duplicated frames
for (var i = 0; i < duplicatedFrames.length - 1; i++) {
duplicatedFrames[i].nextTextFrame = duplicatedFrames[i + 1];
}
// Display a message
alert("Columns split into individual text frames, threaded, and set to single column.");
} else {
alert("Selected text frame does not have multiple columns.");
}
}, undefined, undefined, UndoModes.ENTIRE_SCRIPT);
} else {
alert("Please select a single text frame.");
}
} else {
alert("No open documents.");
}