Skip to main content
Known Participant
October 4, 2024
Answered

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

  • October 4, 2024
  • 3 replies
  • 846 views

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?

This topic has been closed for replies.
Correct answer Stephen Marsh

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);

3 replies

c.pfaffenbichler
Community Expert
Community Expert
October 5, 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. 

Known Participant
October 5, 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.

Stephen Marsh
Community Expert
Community Expert
October 4, 2024

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

 

 

font.postscriptName

// or perhaps

font.postScriptName

 

Known Participant
October 5, 2024

The result I received is: undefined

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
October 5, 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);
Legend
October 4, 2024

Is the active layer a text layer?

Known Participant
October 4, 2024

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