Copy link to clipboard
Copied
Hi All,
I am facing a problem while applying font on paragraph style. Here below is my code.
if (myDoc.paragraphStyles.appliedFont.name == "Helvetica Neue Light")
{
myDoc.paragraphStyles.appliedFont = 'Helvetica Neue LT Std';
myDoc.paragraphStyles.fontStyle = '45 Light';
}
The problem is, you cannot apply "'Helvetica Neue LT Std' because you don't have a style "Light" in that font; and you cannot apply the style
"45 Light" first because you don't have a "Helvetica Neue 45 Light"!
This is what they refer to as a classic "Catch-22" situation. Fortunately, there is another way: you can apply both font and style in one command:
app.activeDocument.paragraphStyles[2].appliedFont = 'Univers LT\t45 Light';
(Note the tab character inbetween font family and style.)
Quite irritat
...Copy link to clipboard
Copied
The problem is, you cannot apply "'Helvetica Neue LT Std' because you don't have a style "Light" in that font; and you cannot apply the style
"45 Light" first because you don't have a "Helvetica Neue 45 Light"!
This is what they refer to as a classic "Catch-22" situation. Fortunately, there is another way: you can apply both font and style in one command:
app.activeDocument.paragraphStyles[2].appliedFont = 'Univers LT\t45 Light';
(Note the tab character inbetween font family and style.)
Quite irritating is that your way does work when applied to text, instead of a paragraph style; for a moment, you'll get a pink text in the "font" [Helvetica Neue 45 Light] and when you apply just the style, all is well again.
Copy link to clipboard
Copied
Thanks Jongware
Its working fine.
Can you please tell me why paragraph and character appliedFont giving different result.
var myDoc = app.activeDocument; var myparastyle = myDoc.paragraphStyles.length; for(a=1; a<myparastyle; a++) { alert (myDoc.paragraphStyles.appliedFont.name) } var mycharstyle = myDoc.characterStyles.length; for(a=1; a<mycharstyle; a++) {....appliedFont.name) }
In paragraph styles its giving font name and font style but in character styles it giving "undefined", Why?
I think result should be same in both cases but its not.
Shonky
Copy link to clipboard
Copied
"Why", well, no idea really.
If you import text, Indesign is happy to add [Unknown Fonts Like This] to paragraph styles, character styles, and to plain text as well. On the other hand, you can't do this in the interface -- if you have a font "Univers LT", you cannot select "Bold" to make it [Univers LT Bold]. Then again, you can using Search and Replace: if your font is Times, you can first replace all "Bold" to "55 Bold", then replace all "Times" to "Univers LT".
It must be something inside the scripting engine. It may well be a too smart programmer, trying to "protect" you from doing this by accident ...
Copy link to clipboard
Copied
Thank you very much.
Shonky
Find more inspiration, events, and resources on the new Adobe Community
Explore Now