2 Replies Latest reply on Jun 1, 2014 7:26 AM by c.pfaffenbichler

    Get gradient color stops data via JavaScript

    venko

      Hi,

       

      Is there a way to retrieve the Color and Location properties of each color stop in a Gradient Overlay (linear gradients only)?

      grad.jpg

      I would like to be PS CS5.1/CS6 compatible.


      Thank you.

        • 2. Re: Get gradient color stops data via JavaScript
          c.pfaffenbichler Level 9

          Maybe this helps:

          // check color stops for gradient overlay;

          // based on code by michael l hale;

          // 2014, use it at your own risk;

          #target photoshop

          if (app.documents.length > 0) {

          var ref = new ActionReference();

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

          var thisDesc = executeActionGet(ref);

          if (thisDesc.hasKey(stringIDToTypeID('layerEffects'))) {

          var layerEffects = thisDesc.getObjectValue(stringIDToTypeID('layerEffects'));

          if (layerEffects.hasKey(stringIDToTypeID('gradientFill'))) {

          var gradientFill = layerEffects.getObjectValue(stringIDToTypeID('gradientFill'));

          var gradient = gradientFill.getObjectValue(stringIDToTypeID('gradient'));

          var colors = gradient.getList(stringIDToTypeID('colors'));

          for (var m = 0; m < colors.count; m++) {

          checkDesc2 (colors.getObjectValue(m))

          }

          }

          }

          };

          //////

          ////// based on code by michael l hale //////

          function checkDesc2 (theDesc) {

          var c = theDesc.count;

          var str = '';

          for(var i=0;i<c;i++){ //enumerate descriptor's keys

            str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';

            };

          alert("desc\n\n"+str);

          };

          ////// check //////

          function getValues (theDesc, theNumber) {

          switch (theDesc.getType(theDesc.getKey(theNumber))) {

          case DescValueType.BOOLEANTYPE:

          return theDesc.getBoolean(theDesc.getKey(theNumber));

          break;

          case DescValueType.CLASSTYPE:

          return theDesc.getClass(theDesc.getKey(theNumber));

          break;

          case DescValueType.DOUBLETYPE:

          return theDesc.getDouble(theDesc.getKey(theNumber));

          break;

          case DescValueType.ENUMERATEDTYPE:

          return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStr ingID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));

          break;

          case DescValueType.INTEGERTYPE:

          return theDesc.getInteger(theDesc.getKey(theNumber));

          break;

          case DescValueType.LISTTYPE:

          return theDesc.getList(theDesc.getKey(theNumber));

          break;

          case DescValueType.OBJECTTYPE:

          return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObject Type(theDesc.getKey(theNumber))));

          break;

          case DescValueType.REFERENCETYPE:

          return theDesc.getReference(theDesc.getKey(theNumber));

          break;

          case DescValueType.STRINGTYPE:

          return theDesc.getString(theDesc.getKey(theNumber));

          break;

          case DescValueType.UNITDOUBLE:

          return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUn itDoubleType(theDesc.getKey(theNumber))));

          break;

          default:

          break;

          };

          };