Skip to main content
Inspiring
April 14, 2023
Answered

Is there a way to manipulate image paths ?

  • April 14, 2023
  • 3 replies
  • 910 views

Hi all.

 

Is there a way to manipulate image paths ?

From the manual it follows that there are 5 types of paths in the image


CLIPPINGPATH, NORMALPATH, TEXTMASK, VECTORMASK, WORKPATH

 

I need to turn NORMALPATH into WORKPATH. Is there a way to do this?

This topic has been closed for replies.
Correct answer Stephen Marsh

If I copy/paste a work path to another doc, it pastes in as a work path.

 

Anyway, it would be easier to make the script work with a normal path from the start, then you don't need to try to convert a saved path to a work path.

3 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
April 14, 2023

If I copy/paste a work path to another doc, it pastes in as a work path.

 

Anyway, it would be easier to make the script work with a normal path from the start, then you don't need to try to convert a saved path to a work path.

AnyONAuthor
Inspiring
April 14, 2023

It is very interesting, if you copy and paste, then we get WORKPATH, and if we drag and drop from document to document, we get NORMALPATH. I was just dragging... But then you can work... Thank you Stephen_A_Marsh

davescm
Community Expert
Community Expert
April 14, 2023

I agree with Stephen, why would you do that?

 

However, if for some reason you do

1. Set the pen tool to path

2. With no path selected in the paths panel place a single point on teh image which will create a workpath

3. In the paths panel click on the path you want to turn into a workpath and press Ctrl +C

4. In the paths panel switch to the workpath and press Ctrl+V

5 Use the path selection tool (black arrow) to select the single point you made in step 1 and delete that point

 

You now have a work path version of your original saved path and can delete the original if required

 

Dave

 

Edit : Stephen added his edit while I was posting

AnyONAuthor
Inspiring
April 14, 2023

Thanks guys for the detailed answer.

I once asked a question on the forumhttps://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-scripting-how-to-put-each-closed-path-on-a-separate-path-layer/td-p/12595798
And JJMack sent me a script that I use in my current work.

Now I need to change the algorithm.
I have two open documents.
In the first one, I draw the WORK PATH, then I copy it to the second image.
But in this second image, this WORK PATH becomes NORMALPATH.

And the JJMack script stops working. It only works with the WORKPATH type.
I tried to change the expressions associated with WORKPATH to NORMALPATH in this script.
But it doesn't give the expected result.

 

-------------------------------------------------------------------------------------------------

function f_WorkPathSeparete(){

    // var workDoc = app.documents[0];
    // app.activeDocument = workDoc;

    try {
        if (app.documents.length > 0) {  
            var myDocument = app.activeDocument;  
            if (myDocument.pathItems.length > 0) {  
                if (!selectedPath()) alert("No Path");
                var thePath = selectedPath();  
                if (thePath != undefined) {  
                    var thePathKind = thePath.kind;  
                    // check if selected path is vector mask;  
                    if (thePathKind == PathKind.VECTORMASK && thePath == myDocument.pathItems[myDocument.pathItems.length - 1]) {var replace = true}
                    else {var replace = false};  
                    var theArray = collectPathInfoFromDesc2012 (myDocument, selectedPath ());  
                    //logInfo(theArray);
                    var theNewArray = new Array;  
                    // creae new array;  
                    for (var m = 0; m < theArray.length; m++) {  
                        var thisSub = theArray[m];  
                        theNewArray.push(new Array);  
                            for (var n = 0; n < thisSub.length - 2; n++) {  
                                var thisPoint = thisSub[n];  
                                //alert( thisPoint[0] + ", " + thisPoint[1] + ", " + thisPoint[2] + ", " + false );
                                theNewArray[0].push([thisPoint[0], thisPoint[1], thisPoint[2], false]);  
                            };  
                        theNewArray[0].push(thisSub[thisSub.length-2]);  
                        theNewArray[0].push(thisSub[thisSub.length-1]);
                        var theNewPath = createPath2015(theNewArray, thePath.name+"p" + m) ;
                        theNewArray = [];                      
                    };  
                    // create copy path;  
                    //logInfo(theNewArray);
                    //var theNewPath = createPath2015(theNewArray, thePath.name+"x")  
                };
            }          
        };  
    }
    catch(e) { alert(e + ': on line ' + e.line, 'Photoshop Error', true); }  
   
    function collectPathInfoFromDesc2012 (myDocument, thePath) {  
    // collect path info from actiondescriptor, smooth added //////  
        var originalRulerUnits = app.preferences.rulerUnits;  
        app.preferences.rulerUnits = Units.POINTS;  
        // based of functions from xbytor’s stdlib;  
        var ref = new ActionReference();  
        for (var l = 0; l < myDocument.pathItems.length; l++) {  
            var thisPath = myDocument.pathItems[l];  
            if (thisPath == thePath && thisPath.kind == PathKind.WORKPATH) {  
                ref.putProperty(cTID("Path"), cTID("WrPt"));  
            };  
            if (thisPath == thePath && thisPath.kind != PathKind.WORKPATH && thisPath.kind != PathKind.VECTORMASK) {  
                ref.putIndex(cTID("Path"), l + 1);  
            };  
            if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {  
                var idPath = charIDToTypeID( "Path" );  
                var idPath = charIDToTypeID( "Path" );  
                var idvectorMask = stringIDToTypeID( "vectorMask" );  
                ref.putEnumerated( idPath, idPath, idvectorMask );  
            };  
        };  
        var desc = app.executeActionGet(ref);  
        var pname = desc.getString(cTID('PthN'));  
        // create new array;  
        var theArray = new Array;  
        var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));  
        // for subpathitems;  
        for (var m = 0; m < pathComponents.count; m++) {  
            var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));  
            var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));  
            switch (operation1) {  
                case 1097098272:  
                var operation = 1097098272 //cTID('Add ');  
                break;  
                case 1398961266:  
                var operation = 1398961266 //cTID('Sbtr');  
                break;  
                case 1231975538:  
                var operation = 1231975538 //cTID('Intr');  
                break;  
                default:  
                // case 1102:  
                var operation = sTID('xor') //ShapeOperation.SHAPEXOR;  
                break;  
            };  
            // for subpathitem’s count;  
            for (var n = 0; n < listKey.count; n++) {  
                theArray.push(new Array);  
                var points = listKey.getObjectValue(n).getList(sTID('points'));  
                try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}  
                catch (e) {var closed = false};  
                // for subpathitem’s segment’s number of points;  
                for (var o = 0; o < points.count; o++) {  
                    var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));  
                    var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];  
                    var thisPoint = [anchor];  
                    try {  
                        var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));  
                        var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];  
                        thisPoint.push(leftDirection)  
                    }  
                    catch (e) {  
                        thisPoint.push(anchor)  
                    };  
                    try {  
                        var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));  
                        var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];  
                        thisPoint.push(rightDirection)  
                    }  
                    catch (e) {  
                        thisPoint.push(anchor)  
                    };  
                    try {  
                        var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));  
                        thisPoint.push(smoothOr)  
                    }  
                    catch (e) {thisPoint.push(false)};  
                    theArray[theArray.length - 1].push(thisPoint);  
                };  
                theArray[theArray.length - 1].push(closed);  
                theArray[theArray.length - 1].push(operation);  
            };  
        };  
        // by xbytor, thanks to him;  
        function cTID (s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };  
        function sTID (s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };  
        // reset;  
        app.preferences.rulerUnits = originalRulerUnits;  
        return theArray;  
    };  
    // create a path from collectPathInfoFromDesc2012-array //////  
    function createPath2015(theArray, thePathsName) {  
        var originalRulerUnits = app.preferences.rulerUnits;  
        app.preferences.rulerUnits = Units.POINTS;  
        // thanks to xbytor;  
        cTID = function(s) { return app.charIDToTypeID(s); };  
        sTID = function(s) { return app.stringIDToTypeID(s); };  
   
   
        var desc1 = new ActionDescriptor();  
        var ref1 = new ActionReference();  
        ref1.putProperty(cTID('Path'), cTID('WrPt'));  
        desc1.putReference(sTID('null'), ref1);  
        var list1 = new ActionList();  
   
        for (var m = 0; m < theArray.length; m++) {  
            var thisSubPath = theArray[m];  
   
            var desc2 = new ActionDescriptor();  
            desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);  
            var list2 = new ActionList();  
            var desc3 = new ActionDescriptor();  
            desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);  
            var list3 = new ActionList();  
   
            for (var n = 0; n < thisSubPath.length - 2; n++) {  
                var thisPoint = thisSubPath[n];  
   
                var desc4 = new ActionDescriptor();  
                var desc5 = new ActionDescriptor();  
                desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);  
                desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);  
                desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);  
                var desc6 = new ActionDescriptor();  
                desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);  
                desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);  
                desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);  
                var desc7 = new ActionDescriptor();  
                desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);  
                desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);  
                desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);  
                desc4.putBoolean(cTID('Smoo'), thisPoint[3]);  
                list3.putObject(cTID('Pthp'), desc4);  
   
            };  
   
            desc3.putList(cTID('Pts '), list3);  
            list2.putObject(cTID('Sbpl'), desc3);  
            desc2.putList(cTID('SbpL'), list2);  
            list1.putObject(cTID('PaCm'), desc2);  
        };  
   
        desc1.putList(cTID('T   '), list1);  
        executeAction(cTID('setd'), desc1, DialogModes.NO);  

        for (var x = 0; x < activeDocument.pathItems.length; x++) {  
            if (activeDocument.pathItems[x].kind == PathKind.WORKPATH) {  
                app.activeDocument.pathItems[x].name = thePathsName;  
                var myPathItem = app.activeDocument.pathItems[x]  
            }  
        };  
        app.preferences.rulerUnits = originalRulerUnits;  
        return myPathItem  
    };
       
    // determine selected path, updated 08.2011 //////  
    function selectedPath () {  
        try {  
            var ref = new ActionReference();  
            ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  
            var desc = executeActionGet(ref);  
            var theName = desc.getString(charIDToTypeID("PthN"));  
            // save work path;  
            // if (app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1].kind == PathKind.WORKPATH || app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1].kind == PathKind.NORMALPATH) {
            if (app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1].kind == PathKind.WORKPATH) {
                // =======================================================  
                var idslct = charIDToTypeID( "slct" );  
                    var desc3 = new ActionDescriptor();  
                    var idnull = charIDToTypeID( "null" );  
                        var ref2 = new ActionReference();  
                        var idPath = charIDToTypeID( "Path" );  
                        var idWrPt = charIDToTypeID( "WrPt" );  
                        ref2.putProperty( idPath, idWrPt );  
                    desc3.putReference( idnull, ref2 );  
                executeAction( idslct, desc3, DialogModes.NO );  
                // =======================================================  
                var idMk = charIDToTypeID( "Mk  " );  
                    var desc4 = new ActionDescriptor();  
                    var idnull = charIDToTypeID( "null" );  
                        var ref3 = new ActionReference();  
                        var idPath = charIDToTypeID( "Path" );  
                        ref3.putClass( idPath );  
                    desc4.putReference( idnull, ref3 );  
                    var idFrom = charIDToTypeID( "From" );  
                        var ref4 = new ActionReference();  
                        var idPath = charIDToTypeID( "Path" );  
                        var idWrPt = charIDToTypeID( "WrPt" );  
                        ref4.putProperty( idPath, idWrPt );  
                    desc4.putReference( idFrom, ref4 );  
                    var idNm = charIDToTypeID( "Nm  " );  
                    desc4.putString( idNm, dateString() );  
                executeAction( idMk, desc4, DialogModes.NO );  
            };  
            //  
            if (theName == "Work Path") {
                return app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1]  
            }  
            else {  
                return app.activeDocument.pathItems.getByName(theName)  
            }  
        }  
        catch (e) {  
            return undefined  
        }  
    };  
       
    // function to get the date //////
    function dateString () {
        var now = new Date();
        var day = now.getDate();
        var month = now.getMonth();
        month++;
        var year = now.getFullYear();
        var hour = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();
        var myDateText = day+"-"+month+"-"+year+"_"+hour+"-"+minutes+"-"+seconds;
        return myDateText
    };

    workDoc.pathItems[0].remove();

    for (var k = 0 ; k < workDoc.pathItems.length; k++) {
        workDoc.pathItems[k].name = k;
    }
    // app.activeDocument = workDoc;
   
}

--------------------------------------------------------------------------------------------------

Stephen Marsh
Community Expert
Community Expert
April 14, 2023

Why? That would be going backwards, from a saved path to an unsaved temporary path. I don't know if that is possible...

 

EDIT: I can sort of hack this by copying the normal path, deleting it, creating a new work path point, pasting the copied path and then deleting the previous work path point.