08.08.14, 15:24
Here's some code to demonstrate a bug in the text ranges when it comes to words within paragraphs. First create a textarea, select it and execute the following code. You can see by the way it sets the fonts and also what is printed to the console.
It seems to get completely mixed up with the ranges.. I'm guessing it has something to do with the carriage returns..?
I'm getting along now by getting the content of the paragraph, .split(" ")'ing it and then getting the subranges based on the lengths of the strings in the array. But it would be nice if this could be fixed..
textbox=activeDocument.selectedItems[0]; textbox.range.content+="rebel comes out in public in Nepalr" textbox.range.content+="Moneycontrol.com, India r" textbox.range.content+=" r" textbox.range.content+="Activists press Nepal's parliament on new constitutionr" textbox.range.content+="Irish Examiner, Irelandr" textbox.range.content+=" r" textbox.range.content+="6:57 am: Nepal's Parliament reconvenes; cease-fire proposedr" textbox.range.content+="Santa Fe New Mexican, NMr" var thefonts=new Array("Times","Courier","Verdana"); var choice=0; print("the number of paragraphs=" + textbox.range.paragraphs.length) for(var p=0; p<textbox.range.paragraphs.length; p++){ for(var w=0; w<textbox.range.paragraphs[p].words.length; w++){ print(textbox.range.paragraphs[p].words[w].content) choice++; if(choice==thefonts.length) choice=0; textbox.range.paragraphs[p].words[w].characterStyle.font=fonts[thefonts[choice]] } }
Cheers!