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

Problem with TextItem.font property

Community Beginner ,
Aug 30, 2015 Aug 30, 2015

Copy link to clipboard

Copied

Hi,

In the following PSD there are two font layers.

FontProblem.psd - Google Drive

The following works correctly on the first font layer, "InputHintWorking".

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

However, gives the following error on the second font layer, "InputHintBroken".

Error 8500: The requested property does not exist.

However, as far as I can tell, there is no difference between the two layers.

Thanks for any guidance you can provide.

Apurva

TOPICS
Actions and scripting

Views

1.1K

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
Adobe
Community Expert ,
Aug 31, 2015 Aug 31, 2015

Copy link to clipboard

Copied

If I remember correctly default properties are ignored in DOM for Type Layers, so if that font should be your default font that would be as expected.

And please post images on this Forum directly.

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 Beginner ,
Aug 31, 2015 Aug 31, 2015

Copy link to clipboard

Copied

Thanks so much for some of these pointers.

If you notice, the layer that works has the same font and style but works just fine. So I am not sure this is related to "default" property.

Also, I can confirm that if I change and revert the property back it works as expected. However, that doesn't seem robust.

Any additional thoughts?

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 ,
Aug 31, 2015 Aug 31, 2015

Copy link to clipboard

Copied

If you changed the font once and back it would not be the default anymore.

I did a quick test and created a Type Layer in a new Document without changing any type properties.

This causes

alert (activeDocument.activeLayer.textItem.font)

to fail, changing the font to another one, committing that change, then changing it to the original font agin caused the alert to work.

A work-around might be to use a try-clause but I don’t know how to determine the document’s current default font in DOM.

Better to go with AM code right away, I guess.

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 Beginner ,
Sep 07, 2015 Sep 07, 2015

Copy link to clipboard

Copied

There is a paragraph style assigned to the layer and when the font name, style, size, color, etc. matches this paragraph style the properties are not stored with the layer itself. So the culprit is paragraph styles not default font setting (not sure if PSD even has that concept...)

I am new to Action Manager scripting so any help to drill down and get the font from the assigned paragraph style via that method would be super helpful. I tried to make some sense out of the script listener log but no joy so far.

BTW, I am already catching exceptions but since there is no paragraph style object in the DOM representation, I still do need to get the font string via AM and don't see any other alternatives.

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 ,
Sep 29, 2015 Sep 29, 2015

Copy link to clipboard

Copied

LATEST

// 2015, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

//

main ();

};

////////////////////////////////////

function main () {

var theFonts = new Array;

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var applicationDesc = executeActionGet(ref);

var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));

//////

for (var m = theNumber; m >= 0; m--) {

try {

var ref = new ActionReference();

ref.putIndex( charIDToTypeID( "Lyr " ), m);

var layerDesc = executeActionGet(ref);

var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));

var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));

var theName = layerDesc.getString(stringIDToTypeID('name'));

// if not layer group collect values;

if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {

var hasText = layerDesc.hasKey(stringIDToTypeID("textKey"));

if (hasText == true) {

var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));

var paragraphRangeList = textDesc.getList(stringIDToTypeID('paragraphStyleRange'));

var kernRange = textDesc.getList(stringIDToTypeID('kerningRange'));

var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));

for (var o = 0; o < rangeList.count; o++) {

var styleDesc = rangeList.getObjectValue(o).getObjectValue(stringIDToTypeID('textStyle'));

// check for default font;

if (styleDesc.hasKey(stringIDToTypeID('fontPostScriptName')) == true) {var aFont = styleDesc.getString(stringIDToTypeID('fontPostScriptName'))}

else {

  var theDefault = styleDesc.getObjectValue(stringIDToTypeID('baseParentStyle'));

  var aFont = theDefault.getString(stringIDToTypeID('fontPostScriptName'));

  };

// add to array;

var theCheck = true;

for (var n = 0; n < theFonts.length; n++) {

if (theFonts == aFont) {theCheck = false}

};

if (theCheck  == true) {theFonts.push(aFont)}

}

}

}

}

catch (e) {};

}

alert ("the result:"+"\n"+theFonts.join("\n"))

};

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
Advisor ,
Sep 07, 2015 Sep 07, 2015

Copy link to clipboard

Copied

I don’t know how to determine the document’s current default font in DOM.

I worked this out for CSII. In http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xlib/psx.jsx you'll find psx.getDefaultFont() and psx.getDefaultTypeToolFont(). Both require Action Manager code. psx.getDefaultTypeToolFont() looks like it is most likely to work regardless of the locale. It has the added benefit that it requires no other code than sTID() and cTID() but I ended up using psx.getDefaultFont() anyway.

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
Enthusiast ,
Aug 31, 2015 Aug 31, 2015

Copy link to clipboard

Copied

I've experienced font properties "getting broken", i.e. trying to access them gives an error. For example I've had cases where the justification value just gives an error until you set it to something else and back, but it seems to be quite rare. I've also taken the habbit of wrapping those access methods in try-catch-finally. Try changing font or recreating the 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