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
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
...
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;
}
Copy link to clipboard
Copied
Thank you for the Script Mark.
Copy link to clipboard
Copied
I will add my research: Illustrator versions below CC 2018 do not have start, end keys in textRanges object.
Copy link to clipboard
Copied
Updating this thread to add that I've lodged two bugs related to this issue. Please vote.
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.