Skip to main content
Thomas Ruesch
Inspiring
November 8, 2017
Question

Applying fontFamily while retaining fontStyle to paragraph Styles

  • November 8, 2017
  • 1 reply
  • 317 views

Hi everybody,

I am working on a script for InDesign that will allow batch operations on several paragraphStyles. Unfortunately, I'm stuck with a particular function. What I'm trying to do is applying a different fontFamily to several paragraphStyles while retaining their current fontStyleName (even if the fontStyleName doesn't exist or isn't loaded in the system for the selected fontFamily). I suspected this to be pretty easy but I can't get it to work properly.

Can you please have a look at the code below and let me know if you understand how InDesign works?

________________________________________________________________________

Example 1

Cycling through all styles (omitting [No style]) -- OK! The paragraphStyle actually shows "Amiri [35 Thin]"

I suspect this is working because the first paragraphStyle ([Paragraphe Standard]) fontStyle was "Regular" and "Amiri Regular" is actually loaded in the system. Look below for code and screenshot of result.

var myPStyles = app.activeDocument.allParagraphStyles;

var myFontFamily = "Amiri";

for (var i=1; i<myPStyles.length; i++) {

     try {myPStyles.appliedFont = myFontFamily+"\t"+myPStyles.fontStyle;}

     catch(err){$.writeln(err);}

}

________________________________________________________________________

Example 2

Cycling through specific paragraphStyles -- DOESN'T WORK The paragraphStyle still shows "Helvetica Neue LT Std 35 Thin"

The first paragraphStyle hasn't been modified because its original fontStyle was "Thin" and "Amiri Thin" isn't loaded in the system (nor does it actually exist).

Is there any way to obtain the same result as in Example 1 without having the need for the first paragraphStyle fontStyle to be valid? (I hope my question makes sense)

var myPStyles = app.activeDocument.allParagraphStyles;

var myFontFamily = "Amiri";

for (var i=2; i<myPStyles.length; i++) {

try {myPStyles.appliedFont = myFontFamily+"\t"+myPStyles.fontStyle;}

catch(err){$.writeln(err);}

}

Returns in the console:

Error: La famille de polices demandée n'est pas disponible.

(Roughly translating to "The requested Font Family is not available")

Any idea how to solve this? Any help is greatly appreciated!

Thomas Rüesch

This topic has been closed for replies.

1 reply

Community Expert
November 8, 2017

Hi Thomas,

hm, I think you cannot apply a font family or a font style that is not loaded in your system ( => available to InDesign) by scripting. There is a workaround, but that requires, that you export IDMS snippets or IDML files and edit the IDMS or IDML files, then import the IDMS files or open the IDML.

Regards,
Uwe

Thomas Ruesch
Inspiring
November 8, 2017

Thank you Uwe!

I understand… But as you can see in the first example, it seems InDesign actually can apply an unloaded fontStyle to a paragraphStyle as long as the font of the first paragraphStyle in the loop is actually available (= loaded in the system). Weird.

I’ll continue investigating and let the forum know if I find a workaround!

Regards,

Thomas