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

Why can't I get the font with this code in Photoshop 2021, while I can retrieve the font in other ve

Participant ,
Oct 04, 2024 Oct 04, 2024

Copy link to clipboard

Copied

alert(app.activeDocument.activeLayer.textItem.font);

 

When my text layer uses the font: Adobe Heiti Std, I want to retrieve the property as: AdobeHeitiStd-Regular using this code. However, on some systems, it cannot be retrieved and shows that the text property cannot be obtained. The version being used is PS 2021. Do you have any solutions for this?

TOPICS
Actions and scripting

Views

253

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

correct answers 1 Correct answer

Community Expert , Oct 04, 2024 Oct 04, 2024

What about this?

 

var ref = new ActionReference();
ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('textKey'));
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
var textDesc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'));
var fontName = textDesc.getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontPostScriptName'));
alert(fontName);

Votes

Translate

Translate
Adobe
LEGEND ,
Oct 04, 2024 Oct 04, 2024

Copy link to clipboard

Copied

Is the active layer a text layer?

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 ,
Oct 04, 2024 Oct 04, 2024

Copy link to clipboard

Copied

Yes, I'm sure it is the active text layer

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
Community Expert ,
Oct 04, 2024 Oct 04, 2024

Copy link to clipboard

Copied

I'm not in front of Photoshop to test, but what do you get with:

 

 

font.postscriptName

// or perhaps

font.postScriptName

 

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 ,
Oct 04, 2024 Oct 04, 2024

Copy link to clipboard

Copied

The result I received is: undefined

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
Community Expert ,
Oct 04, 2024 Oct 04, 2024

Copy link to clipboard

Copied

What about this?

 

var ref = new ActionReference();
ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('textKey'));
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
var textDesc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'));
var fontName = textDesc.getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontPostScriptName'));
alert(fontName);

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 ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

  1. Sorry, the hint is: the requested attribute does not exist.

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 ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

When I use the font: Adobe Heiti Std, and type text in the image, the code will prompt that it cannot retrieve the text attributes. However, when I use a different font and then switch to Adobe Heiti Std, I can retrieve the text attributes.

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
Community Expert ,
Oct 04, 2024 Oct 04, 2024

Copy link to clipboard

Copied

Can you provide a sample-file? 

 

If the result is faulty only on some stations I am not sure the problem can be isolated except on those stations. 

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 ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

LATEST

When I use the font: Adobe Heiti Std, and type text in the image, the code will prompt that it cannot retrieve the text attributes. However, when I use a different font and then switch to Adobe Heiti Std, I can retrieve the text attributes.

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