2 Replies Latest reply on Mar 2, 2016 11:45 PM by Pirlo2222

    How to add a clipping path with Photoshop scripting

    Pirlo2222

      Hi guys,

       

      I'm making a script that is going to save me a lot of time in the future with editing photo's.

       

      When I make a picture of a product it still has a background. When I have the background removed, I want a script to load the layer (so only the product inside the PSD without background) and save the selection as a clipping path. Does anyone know how to do that?

       

      Thanks in advance!

        • 1. Re: How to add a clipping path with Photoshop scripting
          SuperMerlin Level 5

          Something like this....

           

          #target photoshop;
          if(documents.length) main();
          function main(){
          var doc = activeDocument;
          selectLayerData();
          doc.selection.makeWorkPath(0.1);
          doc.pathItems[0].name="Clipping Mask";
          doc.pathItems[0].makeClippingPath(0.5);
          doc.pathItems[0].deselect() 
          doc.selection.deselect();
          }
          function selectLayerData() {
          var desc2 = new ActionDescriptor();
          var ref1 = new ActionReference();
          ref1.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') );
          desc2.putReference( charIDToTypeID('null'), ref1 );
          var ref2 = new ActionReference();
          ref2.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Trsp') );
          desc2.putReference( charIDToTypeID('T   '), ref2 );
          executeAction( charIDToTypeID('setd'), desc2, DialogModes.NO );
          };
          
          
          • 2. Re: How to add a clipping path with Photoshop scripting
            Pirlo2222 Level 1

            SuperMerlin,

             

            Thanks again, you're the best!