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

how can we split text from suggested color to individual text frame?

Engaged ,
Oct 06, 2023 Oct 06, 2023

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

jkhakase_0-1696584342153.pngexpand image

 

TOPICS
How-to , Scripting
612
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 1 Correct answer

Guide , Oct 10, 2023 Oct 10, 2023

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.

10-10-2023.gifexpand image

 

// 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 
...
Translate
Adobe
Guide ,
Oct 06, 2023 Oct 06, 2023

Can you clarify what should precipitate the split?  The color of the text?  A specific sentence fragment? The number of the paragraph?  

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
Engaged ,
Oct 09, 2023 Oct 09, 2023

Expecting to indivisual text frame like this 

jkhakase_1-1696840058931.pngexpand image

 

 

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
Guide ,
Oct 09, 2023 Oct 09, 2023

Yes, but how should the script know to make the splits at these particular places, and not any other places? 

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
Engaged ,
Oct 09, 2023 Oct 09, 2023

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

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
Guide ,
Oct 10, 2023 Oct 10, 2023

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.

10-10-2023.gifexpand image

 

// 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;
}

 

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
Engaged ,
Oct 10, 2023 Oct 10, 2023

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. 

jkhakase_0-1696936810321.pngexpand image

 

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
Guide ,
Oct 11, 2023 Oct 11, 2023

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? 

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
Engaged ,
Oct 11, 2023 Oct 11, 2023
LATEST

Yes, then Normal text which was in Light weight turn to Bold

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