Skip to main content
christophe70958584
Participant
May 17, 2017
Answered

deleting ps-paths automatically

  • May 17, 2017
  • 3 replies
  • 4492 views

Hi, we're using PS CC 2017. Doing lots of images including working paths for retouching purposes we finally want to get rid of those paths if being saved as flat tif. But as far as I know Photoshop only allows to manually select and delete those paths.

 

Is there any workaround to do that automatically with script or Photoshop action.

 

many thanks for any advice!

 

br Christian

This topic has been closed for replies.
Correct answer c.pfaffenbichler

It can be done via a Script, but the following would include a selected Shape Layer, so you could either amend the Script or use it after flattening.

 

// 2017, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

try {activeDocument.pathItems.removeAll()}

catch (e) {}

};

 

Edit: Also see

Path Deletion Script

and maybe post on the Photoshop Scripting Forum.

3 replies

Stephen Marsh
Community Expert
Community Expert
January 27, 2023

I stumbled over this old topic and thought that I should update it with the current code that I use.

 

removeAllClipPaths()

function removeAllClipPaths() {
    // Stephen Marsh, 2022
    // Hide the active layer to ensure that vector shape paths are not inadvertently removed!
    var docPaths = activeDocument.pathItems;
    if (app.activeDocument.activeLayer.isBackgroundLayer) {
        clipPathRemover();
    } else {
        if (activeDocument.activeLayer.visible == false) {
            clipPathRemover();
        } else {
            activeDocument.activeLayer.visible = false;
            clipPathRemover();
            activeDocument.activeLayer.visible = true;
        }
    }

    function clipPathRemover() {
        for (i = docPaths.length - 1; i > -1; i--) {
            thePaths = docPaths[i];
            if (thePaths.kind == "PathKind.CLIPPINGPATH") {
                thePaths.remove()
            }
        }
    }
}

 

removeAllNormalPaths();

function removeAllNormalPaths() {
    // Stephen Marsh, 2022
    // Hide the active layer to ensure that vector shape paths are not inadvertently removed!
    var docPaths = activeDocument.pathItems;
    if (app.activeDocument.activeLayer.isBackgroundLayer) {
        normalPathRemover();
    } else {
        if (activeDocument.activeLayer.visible == false) {
            normalPathRemover();
        } else {
            activeDocument.activeLayer.visible = false;
            normalPathRemover();
            activeDocument.activeLayer.visible = true;
        }
    }

    function normalPathRemover() {
        for (i = docPaths.length - 1; i > -1; i--) {
            thePaths = docPaths[i];
            if (thePaths.kind == "PathKind.NORMALPATH") {
                thePaths.remove()
            }
        }
    }
}

 

removeAllWorkPaths();

function removeAllWorkPaths() {
    // Stephen Marsh, 2022
    // Hide the active layer to ensure that vector shape paths are not inadvertently removed!
    var docPaths = activeDocument.pathItems;
    if (app.activeDocument.activeLayer.isBackgroundLayer) {
        workPathRemover();
    } else {
        if (activeDocument.activeLayer.visible == false) {
            workPathRemover();
        } else {
            activeDocument.activeLayer.visible = false;
            workPathRemover();
            activeDocument.activeLayer.visible = true;
        }
    }

    function workPathRemover() {
        for (i = docPaths.length - 1; i > -1; i--) {
            thePaths = docPaths[i];
            if (thePaths.kind == "PathKind.WORKPATH") {
                thePaths.remove()
            }
        }
    }
}
Kukurykus
Legend
April 22, 2020

Moderator label this thread as 'Actions and scripting'.

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
May 17, 2017

It can be done via a Script, but the following would include a selected Shape Layer, so you could either amend the Script or use it after flattening.

 

// 2017, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

try {activeDocument.pathItems.removeAll()}

catch (e) {}

};

 

Edit: Also see

Path Deletion Script

and maybe post on the Photoshop Scripting Forum.

Stephen Marsh
Community Expert
Community Expert
April 18, 2020

"... but the following would include a selected Shape Layer, so you could either amend the Script ..."

 

Oh, how I have tried, without success since this topic thread:

 

Free script: Remove Selected

stevef55565652
Participant
April 18, 2020

Stephen, could you try this: 

// 2020, use it at your own risk;
if (app.documents.length > 0) {
////// deselect layers //////
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( stringIDToTypeID( "layer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc2.putReference( stringIDToTypeID( "null" ), ref1 );
executeAction( stringIDToTypeID( "selectNoLayers" ), desc2, DialogModes.NO );
////// get paths //////
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref);
if (docDesc.hasKey(stringIDToTypeID("numberOfPaths")) == true) {
var theNumber = docDesc.getInteger(stringIDToTypeID("numberOfPaths"));
var theArray = new Array;
////// work through paths //////
for (var m = 0; m < theNumber+1; m++) {
try {
var ref = new ActionReference();
ref.putIndex( stringIDToTypeID( "path" ), m);
var pathDesc = executeActionGet(ref);
var theName = pathDesc.getString(stringIDToTypeID("pathName"));
var theKind = pathDesc.getEnumerationValue(stringIDToTypeID("kind"));
var theIndex = pathDesc.getInteger(stringIDToTypeID("itemIndex"));
theArray.push([theName, theKind, theIndex]);
} catch (e) {}
};
////// delete //////
for (var n = theNumber-1; n >= 0; n--) {
var desc4 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putIndex( stringIDToTypeID( "path" ), theArray[n][2] );
desc4.putReference( stringIDToTypeID( "null" ), ref2 );
executeAction( stringIDToTypeID( "delete" ), desc4, DialogModes.NO );
};
};
};

This is the first script that I have posted. I have been helped by many other people on this site so I thought I would put this one on.

This is a applescript droplet that deletes all paths and saves the image. Change the tell appplication

"Adobe Photoshop CC 2018" to whatever version of photoshop your using.

This script deletes the first path item while the first path item exists and repeats until there is no first path items.

I had to delete all the paths from the images that I was retouching for work so I made this. It's just pieces of other scripts I found, but seems to work well for me.

Copy the script into Script Editor and export as an application to your desktop and uncheck all 3 options before saving. You can drop your images on it and the paths will be deleted.

 

on open fileList

tell application "Adobe Photoshop CC 2018"

activate

repeat with thisFile in fileList

open thisFile showing dialogs never

try

set myDoc to current document

end try

tell myDoc

repeat while first path item exists

if first path item exists then

delete first path item

end if

end repeat

close saving yes

end tell

end repeat

end tell

end open