Skip to main content
Known Participant
October 4, 2024
解決済み

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.
  • 860 ビュー

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?

このトピックへの返信は締め切られました。
解決に役立った回答 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

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. 

w30290083o9nn作成者
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

 

w30290083o9nn作成者
Known Participant
October 5, 2024

The result I received is: undefined

Stephen Marsh
Community Expert
Stephen MarshCommunity Expert解決!
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?

w30290083o9nn作成者
Known Participant
October 4, 2024

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