Copy link to clipboard
Copied
Hello, I've put together this script that will set the clipping path of a selection to Alpha Channel, convert path to frame, and delete the contents.
for (i=0; i<app.selection.length; i++)
{
try {
app.selection.images[0].clippingPath.clippingType = ClippingPathType.ALPHA_CHANNEL;
} catch (e)
{
// not interested if there is none
}
}
for (i=0; i<app.selection.length; i++)
{
try {
mySel = app.selection
mySel.graphics[0].clippingPath.convertToFrame();
mySel.graphics[0].remove();
} catch (e)
{
// not interested if there is none
}
}
I need to change this to use the Photoshop Path method instead, with a Path Name of "Path 1", but I'm not sure how to do that, can anyone help?
Also, is there a way to specify the clipping path options, specifically "include inside edges" and tolerance/threshold values through script?
Thank you!
Copy link to clipboard
Copied
Hi,
it should be simply:
aImageReference.clippingPath.appliedPathName = 'Path 1'; |
"include inside edges" and tolerance/threshold values -> Valid only when clipping type is alpha channel or detect edges.
Copy link to clipboard
Copied
Thanks for your reply. So I would replace 'ALPHA_CHANNEL' with 'PHOTOSHOP_PATH'. This line of code you sent, where does this fit into my code listed above?
Also, I need to work with both Alpha and PS Paths, so I do need to include inside edges. How can I add that?
Copy link to clipboard
Copied
Hi,
it's not quite clear what your workflow should look like.
So here are just the two examples of how to handle a Photoshoppath (currently on) and alphachannel (currently off).
Assume a image selected:
var currSel = app.selection[0];
(currSel instanceof Image) ? processPath(currSel) : alert('Selection is not a picture.');
//(currSel instanceof Image) ? processAlpha(currSel) : alert('Selection is not a picture.');
//Process a photoshoppath
function processPath(aImageRef)
{
pathNames = aImageRef.clippingPath.photoshopPathNames;
pl = pathNames.length;
while(pl--)
{
if (pathNames[pl] == 'Path 1')
{
aImageRef.clippingPath.appliedPathName = 'Path 1';
alert('Applied Photoshoppath Path 1');
exit();
}
}
}
//process a alphachannel
function processAlpha(aImageRef)
{
//there may be zero to ++ alphachannels, just choosed the first here
var alphaChannelName = aImageRef.clippingPath.alphaChannelPathNames[0];
(alphaChannelName != undefined) ? setAlphaChannel(aImageRef, alphaChannelName) : alert('No Alphachannel avaiable.'); exit();
}
//apply settings for alphaChannel
function setAlphaChannel(aImageRef, alphaChannelName)
{
with (aImageRef.clippingPath)
{
appliedPathName = alphaChannelName;
includeInsideEdges = true;
threshold = 30; //number (range: 0 - 255)
tolerance = 3 ; //number (range: 0 - 10)
restrictToFrame = true;
invertPath = false;
insetFrame = '5 pt';
}
alert('Applied Alphachannel: ' + alphaChannelName);
exit();
}
Happy scripting
Hans-Gerd Claßen
Copy link to clipboard
Copied
Thank you for the help, I tried using this script and I got the message 'selection is not a picture'.
I made a sample layout of what I'm trying to do. I need to be able to select both pictures at the same time, run the script and get the result shown below.
https://www.dropbox.com/s/u3oxbqcpfnkp0n3/sample.indd
The script I posted at the top does everything I need, except it does not include the inside edges.
Copy link to clipboard
Copied
Hi,
my example code expects a image to be selected ... not a graphic frame.
If you spend a bit of your time inspecting it, you'll see that you've got everything to solve your issue either using alpha channel or photoshop path.
Give it a try!
P.S. One tipp: Guess you can forget about the alphachannel as the images have got a photoshop path, which is more accurate -> results would be better.