• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ID UXP script to create Paragraph Style: can not find Font Style

Participant ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

InDesign 18.5, Win 10.

The script (a snippet is given) should create a Paragraph Style that uses the Myriad Pro Bold SemiСondensed font.

 

The problem is that the script somehow cannot find the FontStyle named "Bold Semicondensed". But the specified font style is in the InDesign list and can be manually selected.
The script has no problems with other fonts (Minion Pro Italic), everything works with all their possible styles.

I tried using an instance of the Font object instead of the font family name, but I couldn't figure out how to specify the FontStyle for it. By default, it returns Regular.

Maybe an async call should be used (???), but there's very little information about that...

Here is the script "CreateParaStyle.idjs":

const { 
		app,
		Justification,
		SpanColumnTypeOptions
	  } = require('indesign');
	  
	  let doc = app.documents.add();
	  
	  doc.paragraphStyles.add({
		name: 				"ps_DOI",
		fontFamily: 		"Myriad Pro", 
		fontStyle:  		"Bold SemiCondensed",
		pointSize:			"12pt",
		ligatures:			true,
		justification:		Justification.LEFT_ALIGN,
		minimumWordSpacing: 80,
		desiredWordSpacing:	100,
		maximumWordSpacing: 133,
		spanColumnType:		SpanColumnTypeOptions.SINGLE_COLUMN,
		fillColor: 			"Black"
	  });

 

CaptureID.JPGCaptureID2.JPG

 

Option using Font (needs clarification):

const { 
		app,
		Justification,
		SpanColumnTypeOptions
	  } = require('indesign');
	  
	  let doc = app.documents.add();
	  
	  let fnt = app.fonts.itemByName("Myriad Pro");
	  // HOW TO REQUEST "Bold SemiCondensed" ???
	  
	  doc.paragraphStyles.add({
		name: 				"ps_DOI",
		fontFamily: 		fnt, //"Myriad Pro", 
		fontStyle:  		"Bold SemiCondensed",
		pointSize:			"12pt",
		ligatures:			true,
		justification:		Justification.LEFT_ALIGN,
		minimumWordSpacing: 80,
		desiredWordSpacing:	100,
		maximumWordSpacing: 133,
		spanColumnType:		SpanColumnTypeOptions.SINGLE_COLUMN,
		fillColor: 			"Black"
	  });

 

TOPICS
UXP Scripting

Views

283

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

Try the full name

 

EugeneTyson_0-1691404103265.png

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

Your script should work in respect to the DOM.

Try this, seems too work:

doc.paragraphStyles.add({
		name: 				"ps_DOI",
        appliedFont:"Myriad Pro	Semibold Condensed",
		pointSize:			"12pt",
		ligatures:			true,
		justification:		Justification.LEFT_ALIGN,
		minimumWordSpacing: 80,
		desiredWordSpacing:	100,
		maximumWordSpacing: 133,
		spanColumnType:		SpanColumnTypeOptions.SINGLE_COLUMN,
		fillColor: 			"Black"
	  });

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

Thank you very much! Everything works fine! 

Now I'm wondering if I should replace the use of the two properties "fontFamily" and "fontStyle" with only "appliedFont"...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

Well if it works…

But fontStyle/fontFamily should have worked, probably some UXP weirdness.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

LATEST

try 

let fnt = app.fonts.itemByName("Myriad Pro\tBold SemiCondensed");

that's a tab character between family and style.

Or assign that string directly to the appliedFont property.

If UXPScript works like in ExtendScript in this regard (can't test right now), the following snippet should give some more ideas with a paragraph style configured in the UI. You'll miss its sub-objects, though:

console.log(myPstyle.properties.toSource());

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines