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

Issue while using force line break

Community Beginner ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

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

Views

2.6K

Translate

Translate

Report

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 
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you for the Script Mark.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 ,
Apr 20, 2023 Apr 20, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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