• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Creating Script to select clipping path

New Here ,
Nov 11, 2022 Nov 11, 2022

Copy link to clipboard

Copied

Hi,

 

We have been working on a project where we need to be abe to batch convert a mass of images to png, the issue we have is not all of our paths on images have the same name, we have used the below script in order to get around this so when creating an action instead of selecting Path1 it selects any path:

var doc = activeDocument
doc.pathItems[0].select()

 

We now have another issue, we have images that have multiple paths but we are only interested in selecting the clipping path, is there a script that will select the clipping path over any other path in the image?

TOPICS
Actions and scripting , macOS

Views

501

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 11, 2022 Nov 11, 2022

@tomc39699310 

 

This script will delete all paths which are not clipping paths (including active visible vector shape layer, so use with caution):

 

#target photoshop
if (!documents.length);
for (var a = activeDocument.pathItems.length - 1; a > -1; a--) {
    if (activeDocument.pathItems[a].kind != PathKind.CLIPPINGPATH)
        activeDocument.pathItems[a].remove();
}

 

While this script will select the clipping path:

 

#target photoshop
if (!documents.length);
for (var a = activeDocument.pathI
...

Likes

Translate

Translate
Community Expert ,
Nov 11, 2022 Nov 11, 2022

Copy link to clipboard

Copied

@tomc39699310 

 

This script will delete all paths which are not clipping paths (including active visible vector shape layer, so use with caution):

 

#target photoshop
if (!documents.length);
for (var a = activeDocument.pathItems.length - 1; a > -1; a--) {
    if (activeDocument.pathItems[a].kind != PathKind.CLIPPINGPATH)
        activeDocument.pathItems[a].remove();
}

 

While this script will select the clipping path:

 

#target photoshop
if (!documents.length);
for (var a = activeDocument.pathItems.length - 1; a > -1; a--) {
    if (activeDocument.pathItems[a].kind == PathKind.CLIPPINGPATH)
        activeDocument.pathItems[a].select();
}

 

This one will load a selection from the Clipping Path:

 

#target photoshop
if (!documents.length);
for (var a = activeDocument.pathItems.length - 1; a > -1; a--) {
    if (activeDocument.pathItems[a].kind == PathKind.CLIPPINGPATH)
        activeDocument.pathItems[a].makeSelection();
}

 

Inverse selection from the Clipping Path:

 

#target photoshop
if (!documents.length);
for (var a = activeDocument.pathItems.length - 1; a > -1; a--) {
    if (activeDocument.pathItems[a].kind == PathKind.CLIPPINGPATH)
        activeDocument.pathItems[a].makeSelection();
}
executeAction(stringIDToTypeID( "inverse" ), undefined, DialogModes.NO);

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

Thank you so much for your help I really appreciate you taking the time, its worked perfectly.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2022 Nov 26, 2022

Copy link to clipboard

Copied

LATEST

I believe that I have overcome the issue of an active, visible shape tool path layer being inadvertently removed in this revised version to remove all paths except the nominated clipping path:

 

#target photoshop
var docPaths = activeDocument.pathItems;
if (app.activeDocument.activeLayer.isBackgroundLayer && activeDocument.layers.length == 1) {
    removeNonClippingPaths();
} else if (activeDocument.activeLayer.visible === false) {
    removeNonClippingPaths();
} else {
    activeDocument.activeLayer.visible = false;
    removeNonClippingPaths();
    activeDocument.activeLayer.visible = true;
}
function removeNonClippingPaths() {
        for (i = docPaths.length - 1; i > -1; i--) {
        thePaths = docPaths[i];
        if (thePaths.kind != "PathKind.CLIPPINGPATH") {
            thePaths.remove();
        }
    }
}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines