Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

Issue while using force line break

Community Beginner ,
Jun 07, 2022 Jun 07, 2022

Hi, I have an issue while using force line break in illustrator the forced line break content is created as a new paragraph instead of a line break I have used \n in my script to break the line

TOPICS
Scripting
3.7K
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

Community Expert , Jun 12, 2022 Jun 12, 2022

Hi @SA8888, have a look at this script. I've made a function that tries to solve this problem.

Let me know if it works for you.

- Mark

/*
    Get Paragraphs
    for Adobe Illustrator

    by m1b, here: https://community.adobe.com/t5/illustrator-discussions/issue-while-using-force-line-break/m-p/12996177

    Illustrator treats linefeeds as carriage returns,
    so when you ask a TextRange for paragraphs, it will
    give you too many. This function trys to solve this. 
*/

// example usage:
var 
...
Translate
Adobe
Community Expert ,
Jun 12, 2022 Jun 12, 2022

Hi @SA8888, have a look at this script. I've made a function that tries to solve this problem.

Let me know if it works for you.

- Mark

/*
    Get Paragraphs
    for Adobe Illustrator

    by m1b, here: https://community.adobe.com/t5/illustrator-discussions/issue-while-using-force-line-break/m-p/12996177

    Illustrator treats linefeeds as carriage returns,
    so when you ask a TextRange for paragraphs, it will
    give you too many. This function trys to solve this. 
*/

// example usage:
var paras = getParagraphs(app.activeDocument.selection[0]);
$.writeln(paras[0].contents);
$.writeln(paras[0].lines[1].contents);
$.writeln(paras[0].constructor.name);
$.writeln(paras[1].words[3].contents);


function getParagraphs(obj) {
    if (!obj.hasOwnProperty('story'))
        return
    var story = obj.story,
        text = story.textRange.contents,
        findCarriageReturns = /\u000D/g,
        lastStart = 0,
        paras = [],
        para;

    // add paras between carriage returns
    findCarriageReturns.lastIndex = 0;
    while ((findCarriageReturns.exec(text)) !== null) {
        para = story.textRanges[0];
        para.start = lastStart;
        para.end = findCarriageReturns.lastIndex - 1;
        paras.push(para);
        lastStart = findCarriageReturns.lastIndex;
    }
    // add last paragraph
    if (
        findCarriageReturns.lastIndex > 0
        && findCarriageReturns.lastIndex <= text.length - 1
    ) {
        para = story.textRanges[0];
        para.start = findCarriageReturns.lastIndex;
        para.end = text.length - 1;
        paras.push(para);
    }
    return paras;
}

 

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
Community Beginner ,
Jun 13, 2022 Jun 13, 2022

Thank you for the Script Mark.

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
Enthusiast ,
Apr 12, 2024 Apr 12, 2024
LATEST

I will add my research: Illustrator versions below CC 2018 do not have start, end keys in textRanges object.

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
Community Expert ,
Apr 19, 2023 Apr 19, 2023
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
Mentor ,
Apr 20, 2023 Apr 20, 2023

Interesting observation. Separate paragraphs per force line break should also have implications on the range of applied paragraph styles or paragraph level attributes, and exchange of text with InDesign via CC Library.

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