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

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

Contributor ,
Oct 04, 2024 Oct 04, 2024

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
685
Translate
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);
Translate
Adobe
LEGEND ,
Oct 04, 2024 Oct 04, 2024

Is the active layer a text layer?

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

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

Translate
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

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

 

 

font.postscriptName

// or perhaps

font.postScriptName

 

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

The result I received is: undefined

Translate
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

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);
Translate
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
Contributor ,
Oct 05, 2024 Oct 05, 2024
  1. Sorry, the hint is: the requested attribute does not exist.
Translate
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
Contributor ,
Oct 05, 2024 Oct 05, 2024

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.

Translate
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

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. 

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

Translate
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