Copy link to clipboard
Copied
I have a script that loops through text items on an illustrator page and when it encounters one of a certain size it changes it to a different point size. I would also like to alter the font. The code I have is
if (roundedSize== 7.2) {
item.textRange.characterAttributes.size=9.6;
$.writeln(item.textRange.characterAttributes.textFont)
item.textRange.characterAttributes.textFont="Metric-Semibold"
};
It work fine without the fourth line, but as soon as I try and set a typeface the loop bails. Could someone tell me what I am doing wrong here
Many thanks
Copy link to clipboard
Copied
Hi Bob Haslett,
there are several ways.
One way could be:
item.textRange.characterAttributes.textFont = textFonts.getByName("Metric-Semibold");
Have fun
Copy link to clipboard
Copied
Thanks tha works just as I want it to.
Copy link to clipboard
Copied
Thanks for this solution. I have tried using this, but I get error
var doc = app.activeDocument;
ii= doc.textFrames.add(); //adding text
ii.textRange.characterAttributes.size = 9.5; //character size for text
ii.textRange.characterAttributes.textFont = app.textFonts.getByName("Times");
ii.contents="wwwwww";
I would be grateful for any suggestions.
Copy link to clipboard
Copied
Some notes:
Define your variable for the textFrame (eg var ii = doc... )
Do better not use ii as variable name. This is mostly a 'counter variable'.
Times is not a valid textFont name. Use Times-Roman or Times-Bold instead.
Have fun
Copy link to clipboard
Copied
Thanks a lot, It worked..
Copy link to clipboard
Copied
Can you show the complete code for the above requirement ?
Copy link to clipboard
Copied
var doc = app.activeDocument;
var text1 = doc.textFrames.add();
text1.textRange.characterAttributes.size = 9.5;
text1.textRange.characterAttributes.textFont = app.textFonts["TimesNewRomanPSMT"];
text1.contents = "wwwwww";