Copy link to clipboard
Copied
Hello Friends,
Any idea how can we split text from suggested color to individual text frame. 1st and 2nd bullet has 2 points, 3rd one is single point. that need to be indivisual text frame. any trick or scipt
1 Correct answer
This should split a text frame at the beginning of a paragraph, if the color of the first character of the paragraph is the same as the first character of the first paragraph. Not extensively tested.
// select 1 textFrame
var doc = app.activeDocument;
var sel = doc.selection[0];
var targetColor = sel.paragraphs[0].characters[0].fillColor;
var textFont = sel.textRange.textFont;
var size = sel.textRange.size;
var justification = sel.textRange.justification;
// divide text
var quotients = [];
var
...
Explore related tutorials & articles
Copy link to clipboard
Copied
Can you clarify what should precipitate the split? The color of the text? A specific sentence fragment? The number of the paragraph?
Copy link to clipboard
Copied
Expecting to indivisual text frame like this
Copy link to clipboard
Copied
Yes, but how should the script know to make the splits at these particular places, and not any other places?
Copy link to clipboard
Copied
I think Script should know the applied color at line to identify the place of starting with paragraph and then need to find next line of same color with counting the paragraph
Copy link to clipboard
Copied
This should split a text frame at the beginning of a paragraph, if the color of the first character of the paragraph is the same as the first character of the first paragraph. Not extensively tested.
// select 1 textFrame
var doc = app.activeDocument;
var sel = doc.selection[0];
var targetColor = sel.paragraphs[0].characters[0].fillColor;
var textFont = sel.textRange.textFont;
var size = sel.textRange.size;
var justification = sel.textRange.justification;
// divide text
var quotients = [];
var lines = 0, contents = "", colors = [];
for (var i = sel.paragraphs.length - 1; i > -1; i--) {
try {
lines = sel.paragraphs[i].lines.length + lines;
if (sel.paragraphs[i].contents == "") continue;
contents = sel.paragraphs[i].contents + "\n" + contents;
subcolors = [];
for (var j = 0; j < sel.paragraphs[i].characters.length; j++) {
subcolors.push(sel.paragraphs[i].characters[j].fillColor);
}
subcolors.push(undefined); // color corresponding to linebreak
// null crashes Illustrator
colors = subcolors.concat(colors);
if (areEqual(sel.paragraphs[i].characters[0].fillColor, targetColor)) {
var quotient = {};
quotient.lines = lines;
quotient.contents = contents;
quotient.colors = colors;
quotients.push(quotient);
lines = 0, contents = "", colors = [];
}
} catch (e) {
}
}
// re-draw textFrames
var precedingHeight = sel.geometricBounds[1];
for (var i = quotients.length - 1; i > -1; i--) {
var lines = quotients[i].lines;
var height = lines * sel.textRange.characterAttributes.leading;
var rect = doc.pathItems.rectangle(
precedingHeight, sel.geometricBounds[0], sel.width, height);
precedingHeight -= height;
var textFrame = doc.textFrames.areaText(rect);
textFrame.contents = quotients[i].contents;
textFrame.textRange.textFont = textFont;
textFrame.textRange.size = size;
textFrame.textRange.justification = justification;
for (var j = 0; j < textFrame.characters.length; j++) {
if (quotients[i].colors[j] == undefined) continue;
else textFrame.characters[j].fillColor = quotients[i].colors[j];
}
}
sel.remove();
function areEqual(o1, o2) {
for (var k in o1) {
if (o1[k] != o2[k]) return false;
}
for (var k in o2) {
if (o1[k] != o2[k]) return false;
}
return true;
}
Copy link to clipboard
Copied
Awesome! Perfectly working as I expect the seperation of text frames, Thank you so much @femkeblanco , I just found one issue its changing the font weight, I think it should be consistent. but whatever you have done its amezing, I didn't found such script on the net.
Copy link to clipboard
Copied
I can't explain this, as the script copies the text's original font and font size. What is actually changing, the font style (e.g. to bold) or the font size?
Copy link to clipboard
Copied
Yes, then Normal text which was in Light weight turn to Bold
![](/skins/images/AA97151791FDED2C2AF9AE8AE14B8212/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/AA97151791FDED2C2AF9AE8AE14B8212/responsive_peak/images/icon_anonymous_message.png)