Copy link to clipboard
Copied
Hello
Please may someone inform me if scripting using JSX for InDesign allows for the copy and pasting of the formatt of text.
For example I have made a script which can break a single text frame devided into many equal separate text columns (as adobe are super poor at giving usful tools) - but when the text appears in the separate threaded boxes the formattting is gone
the script replaces the single text frame box with separate text frame boxes and pastes back in the text
but i cannot make it paste with the og formatting - interesting only justfication will be pasted as it is not a character format etc
also i have made a script where a user can just select unthreaded boxes and it will auto thread
but again for some reason formatting is losst and altered even though no copy paste funtion should be happening
any ideas why it is so difficult thanks
Copy link to clipboard
Copied
In your script, please check if you are setting the "contents" of a text object. If so, then you will often lose the formatting. Instead have a look at using .move or .duplicate. An example using duplicate is in my script from this post.
- Mark
Copy link to clipboard
Copied
Thank you
I will have a look shortly
May thanks
Copy link to clipboard
Copied
You should include your code, but sounds like you need to use the text frame .duplicate method to create your copies rather than whatever you're doing.
Copy link to clipboard
Copied
Hello,
Thank you for the feeback.
Allow me to look into this. Does that allow for the formatting of text to be retained, for example text in which the font size and colour and so on may be modified by a user where they do not use paragraph or character styles?
Best
Copy link to clipboard
Copied
I have a script that breaks a multi-column text frame into individual threaded frames. There's no copying and pasting, the story just flows from one frame to the next with styling intact. Would that help?
Copy link to clipboard
Copied
Hello Robert
Thank you for your feedback, yes that is very interesting.
Would be kind enough to provide me with the code so I can learn from it.
Best
Smyth
Copy link to clipboard
Copied
This was the code I had
It doesn't yet have the abilty to keep formatting
however ChatGPT did suggest somelines - means nothing to me and it didnt work
// 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;
var prevFrame = null;
for (var i = 0; i < columns.length; i++) {
var newFrame = selectedTextFrame.parentPage.textFrames.add();
var newX1 = selectedTextFrame.geometricBounds[1] + (columnWidth + gutter) * i;
var newX2 = newX1 + columnWidth;
newFrame.geometricBounds = [selectedTextFrame.geometricBounds[0], newX1, selectedTextFrame.geometricBounds[2], newX2];
// Copy the content from the story for each new frame
var copiedText = story.contents;
newFrame.contents = copiedText;
if (prevFrame) {
prevFrame.nextTextFrame = newFrame;
}
prevFrame = newFrame;
}
// Remove the original multi-column text frame
selectedTextFrame.remove();
// Display a message
alert("Columns split into individual text frames and threaded.");
} 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.");
}
lets keep everything in the aboe the same but lets retain some formating properties of the text when copied
// Copy font size and font color
targetChar.contents = sourceChar.contents;
targetChar.appliedFont = sourceChar.appliedFont;
targetChar.fillColor = sourceChar.fillColor;