Skip to main content
Known Participant
March 2, 2016
Answered

How to add a clipping path with Photoshop scripting

  • March 2, 2016
  • 1 reply
  • 938 views

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!

This topic has been closed for replies.
Correct answer SuperMerlin

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 );

};

1 reply

SuperMerlin
SuperMerlinCorrect answer
Inspiring
March 2, 2016

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 );

};

Pirlo2222Author
Known Participant
March 3, 2016

SuperMerlin,

Thanks again, you're the best!