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

Stephen Marsh
Community Expert
Community Expert
April 19, 2020

I just revised this and it keeps all layers including the shape layer and shape layer path but deletes all other paths. I just added a command to turn off all layers in photoshop, run the path deletion part of the script and then turn all layers back on and then save.

 

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 application "System Events" to tell process "Adobe Photoshop CC 2018"

set frontmost to true

keystroke "a" using {option down, command down}

keystroke "," using {command down}

end tell

tell myDoc

repeat while first path item exists

if first path item exists then

delete first path item

end if

end repeat

tell application "Adobe Photoshop CC 2018"

activate

tell application "System Events" to tell process "Adobe Photoshop CC 2018"

set frontmost to true

keystroke "," using {command down}

end tell

end tell

close saving yes

end tell

end repeat

end tell

end open


"I just added a command to turn off all layers in photoshop, run the path deletion part of the script and then turn all layers back on and then save."

 

Thank you stevef55565652 that is a very clever idea!

 

Although JS can't send keystrokes, I can emulate these steps using menu calls or script listener code.

 

I see two small issues, it would be better if they were overcome... The initial layer visibility is altered and initial layer selections are altered. So now all I need to do is find out how to capture and restore the initial layer array visibility and selected/targeted layers so that the original document layers are not affected after removing all non-clipping paths (for example) while retaining shape layers.