4 Replies Latest reply on May 13, 2014 10:03 PM by Trevorׅ

    Reg finding type of swatch

    Naren raj

      Hi,

       

      Is there any code for finding the "tint" and "gradient" used in swatches. I have checked in many way but I could not find it.

       

      Regards

      Raj

        • 1. Re: Reg finding type of swatch
          Jump_Over Level 5

          Hi,

           

          Have to getElements() for particular swatch and check its constructor.name

          Example:

          var
            mS = app.activeDocument.swatches.everyItem().getElements(),
            len = mS.length;
          
          while (len-->0) {
            switch (mS[len].constructor.name) {
               case "Tint":
                    alert ("Swatch " + mS[len].name + " is a tint");
                    break;
               case "Gradient":
                    alert ("Swatch " + mS[len].name + " is a gradient");
                    break;
                    }
               }
          

           

          Jarek

          • 2. Re: Re: Reg finding type of swatch
            Trevorׅ Adobe Community Professional

            I think you might find this useful

            var doc = app.activeDocument,
                mySwatches = doc.swatches.everyItem().getElements().slice(0),
                myTint = doc.tints[0],
                myGradient = doc.gradients[0],
                l = mySwatches.length, a = [], swatchType;
            if (myTint.isValid) {
                alert("Tint Swatch\r****************\r" +myTint.properties.toSource())
            }
            
            if (myGradient.isValid) {
                alert("Gradient Swatch\r****************\r" +
                        myGradient.properties.toSource() +
                       "\r\rGradient Stops\r****************\r" +
                       myGradient.gradientStops.everyItem().properties.toSource()
                       )
            }
            if (l) {
                while (l--) {
                  if (mySwatches[l] .hasOwnProperty  ("tintValue")) swatchType = "tint";
                  else if (mySwatches[l] .hasOwnProperty  ("gradientStops")) swatchType = "gradient";
                  else swatchType = "regular"
                  a[l] = "Swatch: " + mySwatches[l].name + " is a " + swatchType + " swatch";
                }
                alert (a.join("\r"));
            }
            
            
            • 3. Re: Re: Reg finding type of swatch
              Naren raj Level 1

              Thanks Trevor

              • 4. Re: Re: Reg finding type of swatch
                Trevorׅ Adobe Community Professional

                Pleasure, please mark as answered.

                Greenshot_2014-04-03_01-48-49.png

                Thanks