1 Reply Latest reply on Aug 27, 2013 8:46 AM by Tom Ruark

    Getting weird error: "General Photoshop error occurred".

    _VG Level 1

      Hi Guys,

       

      I am trying to get the info(font, color, alignment etc.)  of text kind layer in Photoshop CC. My script is as follows,

       

      var textLayer = activeDocument.activeLayer.textItem;

      var fontName = textLayer.font;

      try{

           var textColor = "R: " + textLayer.color.rgb.red + " G: " + textLayer.color.rgb.green + " B: " + textLayer.color.rgb.blue;

      }

      catch(e){alert(e);}

      try

      {

           var textAlignment = textLayer.justification.toString();

      }

      catch(e){alert(e);}

       

      On setting the color value R - 0, B - 0 and G - 0 or alignment 'Left' and create a text layer after this. I encountered an error

       

      "Error: General Photshop error occurred. This functionality may not be available in this version of Photoshop.

           - <no additional information available> "

       

      If I set some other color value and other alignment and create the text and get its info, script works fine.

      Or If I change the values and revert it back to 'Left' alignment and R-0, B-0 and G-0 then I am able to get the values with the above script.

      I get this error at first time only and after that script works fine

       

      I also run this script with CS5 version, Its working fine there. But I don't know why I am getting this error in CC version.

      Am I doing something wrong here or Is it some issue with Photoshop CC.

       

      Any help would be appriciated.

      Thanks..

        • 1. Re: Getting weird error: "General Photoshop error occurred".
          Tom Ruark Adobe Employee

          Is your text layer using a layer style? If so, this routine should find the font and color in use.

           

          var fontsInUse = [];

          var colorsInUse = [];

           

           

          if ( documents.length > 0 ) {

           

              GetFontUsage( activeDocument.layers, fontsInUse );

             

                    alert( fontsInUse );

           

           

              GetColorUsage( activeDocument.layers, colorsInUse );

           

           

                    alert( colorsInUse );

           

           

          } else {

                    alert( "Please open a document." );

          }

           

           

           

           

          function GetFontUsage( l, f ) {

              for ( var i = 0; i < l.length; i++ ) {

                  if ( l[i].typename == "LayerSet" ) {

                      GetFontUsage( l[i].layers, f );

                  } else if ( l[i].typename == "ArtLayer" && l[i].kind == LayerKind.TEXT  ) {

                      try {

                          f.push( l[i].textItem.font );

                      }

                      catch(e) {

                          f.push( GetFontUsageFromDescriptor( l[i] ) );

                      }

                  }

              }

          }

           

           

          function GetColorUsage( l, f ) {

              for ( var i = 0; i < l.length; i++ ) {

                  if ( l[i].typename == "LayerSet" ) {

                      GetFontUsage( l[i].layers, f );

                  } else if ( l[i].typename == "ArtLayer" && l[i].kind == LayerKind.TEXT  ) {

                      try {

                          f.push( Math.round(l[i].textItem.color.rgb.red) + ":" +

                                  Math.round(l[i].textItem.color.rgb.green) + ":" +

                                  Math.round(l[i].textItem.color.rgb.blue));

                      }

                      catch(e) {

                          f.push( GetColorUsageFromDescriptor( l[i] ) );

                      }

                  }

              }

          }

           

           

          // text layer probably has a layer style

          // we will try to select the layer

          // pull the descriptor

          // and see if we can find a font

          function GetFontUsageFromDescriptor( l ) {

              var layerFontName = "";

             

              var lastActive = activeDocument.activeLayer;

              activeDocument.activeLayer = l;

             

              var ktextKeyStr = stringIDToTypeID("textKey");

                    var ref = new ActionReference();

                    ref.putProperty(charIDToTypeID('Prpr'), ktextKeyStr);

                    ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'),

                                                                                                                                            charIDToTypeID('Trgt'));

                    var desc = executeActionGet(ref);

           

                    if ( desc.hasKey( ktextKeyStr ) ) {

                              var descText = desc.getObjectValue( ktextKeyStr );

                  var kparagraphStyleRangeStr = stringIDToTypeID( "paragraphStyleRange" );

                  if ( descText.hasKey( kparagraphStyleRangeStr ) ) {

                      var paraList = descText.getList(  kparagraphStyleRangeStr );

                      var kparagraphStyleStr = stringIDToTypeID("paragraphStyle");

                      var paraDesc = paraList.getObjectValue( 0 );

                      if ( paraDesc.hasKey( kparagraphStyleStr ) ) {

                          var paraStyle = paraDesc.getObjectValue( kparagraphStyleStr );

                          var kdefaultStyleStr = stringIDToTypeID("defaultStyle");

                          if ( paraStyle.hasKey( kdefaultStyleStr ) ) {

                              var defStyle = paraStyle.getObjectValue( kdefaultStyleStr );

                              var kfontPostScriptNameStr = stringIDToTypeID("fontPostScriptName");

                              if ( defStyle.hasKey( kfontPostScriptNameStr ) ) {

                                  layerFontName = defStyle.getString( kfontPostScriptNameStr );

                              }

                          }

                      }

                  }

                    }

           

           

              activeDocument.activeLayer = lastActive;

           

           

              return layerFontName;

          }

           

           

          // text layer probably has a layer style

          // we will try to select the layer

          // pull the descriptor

          // and see if we can find a color

          function GetColorUsageFromDescriptor( l ) {

              var layerColor = "";

             

              var lastActive = activeDocument.activeLayer;

              activeDocument.activeLayer = l;

             

              var ktextKeyStr = stringIDToTypeID("textKey");

                    var ref = new ActionReference();

                    ref.putProperty(charIDToTypeID('Prpr'), ktextKeyStr);

                    ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'),

                                                                                                                                            charIDToTypeID('Trgt'));

                    var desc = executeActionGet(ref);

           

                    if ( desc.hasKey( ktextKeyStr ) ) {

                              var descText = desc.getObjectValue( ktextKeyStr );

                  var kparagraphStyleRangeStr = stringIDToTypeID( "paragraphStyleRange" );

                  if ( descText.hasKey( kparagraphStyleRangeStr ) ) {

                      var paraList = descText.getList(  kparagraphStyleRangeStr );

                      var kparagraphStyleStr = stringIDToTypeID("paragraphStyle");

                      var paraDesc = paraList.getObjectValue( 0 );

                      if ( paraDesc.hasKey( kparagraphStyleStr ) ) {

                          var paraStyle = paraDesc.getObjectValue( kparagraphStyleStr );

                          var kdefaultStyleStr = stringIDToTypeID("defaultStyle");

                          if ( paraStyle.hasKey( kdefaultStyleStr ) ) {

                              var defStyle = paraStyle.getObjectValue( kdefaultStyleStr );

                              var kColorStr = stringIDToTypeID("color");

                              if ( defStyle.hasKey( kColorStr ) ) {

                                  var colorDesc = defStyle.getObjectValue( kColorStr );

                                  layerColor += Math.round( colorDesc.getInteger( stringIDToTypeID("red" ) ) ) + ":";

                                  layerColor += Math.round( colorDesc.getInteger( stringIDToTypeID("green" ) ) ) + ":";

                                  layerColor += Math.round( colorDesc.getInteger( stringIDToTypeID("blue" ) ) );

                              }

                          }

                      }

                  }

                    }

           

           

              activeDocument.activeLayer = lastActive;

           

           

              return layerColor;

          }