7 Replies Latest reply on Dec 21, 2015 2:21 AM by c.pfaffenbichler

    Problem with TextItem.font property




      In the following PSD there are two font layers.

      FontProblem.psd - Google Drive


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



      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.



        • 1. Re: Problem with TextItem.font property
          c.pfaffenbichler Level 9

          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.

          1 person found this helpful
          • 2. Re: Problem with TextItem.font property
            matias.kiviniemi Level 3

            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.

            1 person found this helpful
            • 3. Re: Problem with TextItem.font property
              spyarjun Level 1

              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?

              • 4. Re: Problem with TextItem.font property
                c.pfaffenbichler Level 9

                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.

                • 5. Re: Problem with TextItem.font property
                  spyarjun Level 1

                  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.

                  • 6. Re: Problem with TextItem.font property
                    xbytor2 Level 4

                    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.

                    • 7. Re: Problem with TextItem.font property
                      c.pfaffenbichler Level 9

                      // 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[n] == aFont) {theCheck = false}


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





                      catch (e) {};


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