Issue while using force line break
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, 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
Hey Mark, Can you help with the script for Paragraph objects and also allow us to take only 3 paragraphs in a text frame instead of 5 paragraphs.
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;
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.