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

Stroke individual subpaths via scripting

Community Beginner ,
Feb 07, 2018 Feb 07, 2018

Copy link to clipboard

Copied

Hello

I am trying to write a script that would stroke each subpath within one path with a color sampled from the image at a position of the anchor point of each subpath.

I was able to go through the subpaths and get the coordinates of their anchor points and change the foreground color to those sampled colors. What I cannot solve is how to stroke individual subpaths with different colors. The method strokePath only applies to the whole path and strokes all subpaths with the same color.

Currently my script takes each subpath and copies it into a new path and strokes that new path. The problem is that this is incredibly slow. The path was created by vectoriastion of a bitmap image and contains thousands of subpaths and each subpath consists of many points. Copying all that into new paths takes time that I cannot afford. I tried using Script Listener to record the action of selecting a subpath and then stroking a subpath, because this is manually possible in Photoshop GUI, however I cannot bend the script made by Listener to parametrize it and make it work in a for cycle over all subpaths.

So my question basically is: Is it possible to script stroking a subpath?

I would be very grateful for any tips, I have been looking for answers everywhere but never came across a similar problem.

Thank you.

This is my current script:

#target photoshop

function extractSubPathInfo(pathObj, doc){ 

    // number of subpaths

    var pl = pathObj.subPathItems.length;

   

    for(var s=0;s<pl;s++){ 

       

        var pathArray = [];

        var pArray = []; 

       

        // copying each subpath into a new path

        for(var i=0;i<pathObj.subPathItems.pathPoints.length;i++){ 

             

             pArray = new PathPointInfo; 

             pArray.kind = pathObj.subPathItems.pathPoints.kind; 

             pArray.anchor = pathObj.subPathItems.pathPoints.anchor; 

             pArray.leftDirection = pathObj.subPathItems.pathPoints.leftDirection; 

             pArray.rightDirection = pathObj.subPathItems.pathPoints.rightDirection;

            

          }; 

     

        pathArray[pathArray.length] = []; 

        pathArray[pathArray.length - 1] = new SubPathInfo(); 

        pathArray[pathArray.length - 1].operation = pathObj.subPathItems.operation; 

        pathArray[pathArray.length - 1].closed = pathObj.subPathItems.closed; 

        pathArray[pathArray.length - 1].entireSubPath = pArray; 

       

       

        var newPath = doc.pathItems.add("New"+s.toString(), pathArray);

       

        // setting the foreground color to a sampled color from the position of anchor point of the subpath

        var SubPath = newPath.subPathItems[0];

        var InputPoint = SubPath.pathPoints[0]; 

        var x = InputPoint.anchor[0];

        var y = InputPoint.anchor[1];

        var theSampler = doc.colorSamplers.add([x,y]);                

        app.foregroundColor = theSampler.color;

          

         // stroke the new path

        newPath.strokePath(ToolType.BRUSH, 1);    

        

         // remove the color sample and the new path

        app.activeDocument.colorSamplers.removeAll();             

        newPath.remove();

       

    };

    return ; 

}; 

function main () {

   

// Get current document and current layer

var doc = app.activeDocument;

var PathItems = doc.pathItems;

var PathNum =   PathItems.length; 

// change work path into a normal path

try {

    activeDocument.pathItems.getByName("Work Path").name="Path " + activeDocument.pathItems.length;

    }

catch (Exception) {}

// set ruler units to pixels for the color sampler

var startRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// Nothing to do if the active layer has no path

    if (PathNum == 0)

        return;

         

// for each path in the path items

for (var i = 0; i < PathNum ; ++i)

    {

        var Path = PathItems;

        extractSubPathInfo(Path, doc);

    }

app.preferences.rulerUnits = startRulerUnits;

} //end of main function

main();

TOPICS
Actions and scripting

Views

2.5K

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 , Feb 09, 2018 Feb 09, 2018

As far as I can tell creating new (temporary) paths for each subPathItem to stroke it individually is unavoidable for this.

But using AM code instead of DOM code should speed things up some.

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

As far as I can tell creating new (temporary) paths for each subPathItem to stroke it individually is unavoidable for this.

But using AM code instead of DOM code should speed things up some.

Votes

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 ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

I agree with c.pfaffenbichler, you can't actually select a subpath in PS, you have to take the subpath info and create a new path. I ran into this issue also. I wanted to do something along the lines that you're talking about, but I wanted to take closed subpaths, create a selection of each of them, then use the average filter to blur the contents of a layer. I had created the original path in Illustrator using it's effects panel, but I couldn't import it into PS as separate paths. I ended up writing a script in IA that recorded all the path info to an XML file that I could then use in PS to recreate the paths.

067a-Uebele.jpg

Votes

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 Beginner ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

Thank you both very much, I kind of figured that selecting subpaths in PS via scripting wouldn't be possible but I tried asking the more ecperienced ones I will try to use the AM code instead of PS DOM, thanks for the tip!

Votes

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 ,
Feb 11, 2018 Feb 11, 2018

Copy link to clipboard

Copied

Below should stroke all subPathItems of the selected Path.

Though I guess it might prove prudent to first collect the colors in a separate step to avoid using colors that have already been altered.

strokeSubPathItemsScr.jpg

// stroke supathitems with color from first point;

// 2018, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

try {

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var pathDesc = executeActionGet(ref);

var pathComponents = pathDesc.getObjectValue(charIDToTypeID("PthC")).getList(stringIDToTypeID('pathComponents'));

// for each subpathitem;

for (var m = 0; m < pathComponents.count; m++) {

var listKey = pathComponents.getObjectValue(m);

var thePoint = listKey.getList(stringIDToTypeID("subpathListKey")).getObjectValue(0).getList(stringIDToTypeID("points")).getObjectValue(0).getObjectValue(stringIDToTypeID("anchor"));

var theHor = thePoint.getUnitDoubleValue(stringIDToTypeID("horizontal"));

var theVer = thePoint.getUnitDoubleValue(stringIDToTypeID("vertical"));

// work path;

var desc1 = new ActionDescriptor();

var ref1 = new ActionReference();

ref1.putProperty(charIDToTypeID('Path'), charIDToTypeID('WrPt'));

desc1.putReference(charIDToTypeID('null'), ref1);

var list1 = new ActionList();

list1.putObject(charIDToTypeID('PaCm'), listKey);

desc1.putList(charIDToTypeID('T   '), list1);

executeAction(charIDToTypeID('setd'), desc1, DialogModes.NO);

// set sampler;

/*try {

var theSampler = activeDocument.colorSamplers.add([theHor, theVer]);

var theColor = theSampler.color;

theSampler.remove();

app.foregroundColor = theColor;

} catch (e) {};*/

// set color sampler;

var desc15 = new ActionDescriptor();

var ref5 = new ActionReference();

ref5.putClass( charIDToTypeID( "ClSm" ) );

desc15.putReference( charIDToTypeID( "null" ), ref5 );

var desc16 = new ActionDescriptor();

var idPxl = charIDToTypeID( "#Pxl" );

desc16.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, theHor );

desc16.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, theVer );

desc15.putObject( charIDToTypeID( "Pstn" ), charIDToTypeID( "Pnt " ), desc16 );

executeAction( charIDToTypeID( "Mk  " ), desc15, DialogModes.NO );

// get color sampler;

var ref = new ActionReference();

ref.putProperty(stringIDToTypeID ("property"), stringIDToTypeID("colorSamplerList"));

ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var docDesc = executeActionGet(ref);

var colorSamplers = docDesc.getList(stringIDToTypeID("colorSamplerList"));

var theIndex = colorSamplers.count;

// doregroun dcolor;

var desc8 = new ActionDescriptor();

var ref3 = new ActionReference();

ref3.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "FrgC" ) );

desc8.putReference( charIDToTypeID( "null" ), ref3 );

var desc9 = new ActionDescriptor();

desc9.putDouble( charIDToTypeID( "Rd  " ), colorSamplers.getObjectValue(theIndex-1).getObjectValue(stringIDToTypeID("color")).getDouble(stringIDToTypeID("red")) );

desc9.putDouble( charIDToTypeID( "Grn " ), colorSamplers.getObjectValue(theIndex-1).getObjectValue(stringIDToTypeID("color")).getDouble(stringIDToTypeID("green")) );

desc9.putDouble( charIDToTypeID( "Bl  " ), colorSamplers.getObjectValue(theIndex-1).getObjectValue(stringIDToTypeID("color")).getDouble(stringIDToTypeID("blue")) );

desc8.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "RGBC" ), desc9 );

executeAction( charIDToTypeID( "setd" ), desc8, DialogModes.NO );

// stroke path;

var desc4 = new ActionDescriptor();

var ref1 = new ActionReference();

ref1.putEnumerated( charIDToTypeID( "Path" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

desc4.putReference( charIDToTypeID( "null" ), ref1 );

desc4.putClass( charIDToTypeID( "Usng" ), charIDToTypeID( "PbTl" ) );

desc4.putBoolean( charIDToTypeID( "Prs " ), true );

executeAction( charIDToTypeID( "Strk" ), desc4, DialogModes.NO );

// remove color sample;

var desc19 = new ActionDescriptor();

var ref6 = new ActionReference();

ref6.putIndex( charIDToTypeID( "ClSm" ), theIndex );

desc19.putReference( charIDToTypeID( "null" ), ref6 );

executeAction( charIDToTypeID( "Dlt " ), desc19, DialogModes.NO );

};

} catch (e) {};

app.preferences.rulerUnits = originalRulerUnits;

};

Votes

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 ,
Feb 11, 2018 Feb 11, 2018

Copy link to clipboard

Copied

Usually when I do things like this, I do make a base layer as a reference.

Votes

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 ,
Feb 12, 2018 Feb 12, 2018

Copy link to clipboard

Copied

Though reading the colors from that layer would probably necessitate selecting it for each color-picking, so it might have a slight performance effect.

Votes

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 ,
Feb 10, 2018 Feb 10, 2018

Copy link to clipboard

Copied

Also remember that if you have lots of subpatrhs, you can only have 200 main paths.

Votes

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 Beginner ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

Wow, thank you so much for the AM code, it works perfectly, double the speed of the DOM one, really thank you so much.

The setting of my project is that there is a base layer to pick colors from and a new layer where the stroke path are drawn, so I just added "hide layer" action before the color sampler picks the color, to make sure it picks it from the base layer, and then show it again before the stroke path part of the script comes and everything works great, thank you, you guys are great!

Votes

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
LEGEND ,
Mar 04, 2018 Mar 04, 2018

Copy link to clipboard

Copied

I wrote a script to see is it possible to read paths from binaries, then store to array to apply by Action Manager. It is, however that wasn't easy, took me some time, and I had to find solutions some bugs I experienced weren't arising. Of course that can be fully made with Action Manager (so reading and applaying subpaths), but main goal was like I said to do something what wasn't posted anywhere - to do the same more complex way. It works much faster than Domestic Object Model, but slower than Action Manager. But reading binaries doesn't slow it really down. It's still fast. The slowest process is using by AM data stored in array. With a path that has many subpaths it is a little slower than doing it only with AM, but when some subpath contains over large amount of points then it slows down. I didn't test it much yet but for ex. when one subpath got 3 * 706 (leftDirections, anchors, rightDirections) where each has horizontal and vertical position then it was still very fast but when other got 3 * 2611 (rest same like before), then it dramatically slowed down! 1500(?) * (all kind of) points is still much, and in future if I modify script it gives chance to apply paths from unopened files! So for example you could have stored some files with paths which (sub)paths you wanted to browse by script but without opening files that contain them to apply to current document you work on. It works now for a file named pat.psd that's saved on desktop. Later this limitation will be changed!

This is experimental script so if anyone want to try it remember to have only one Path named "Path A" with any number of any kind subpaths. Later I test it with more paths, but now I want you too see you find some bugs in the bacis beta version.

When it's tested I'm going to do another undone by noone thing yet. Read bitmap data from written file to complete task of this topic, so read colour of pixels that are under first point of each subpath (so the hardest part) to apply them to subpaths.

You'll see some magic with this script. When your document has path with some subpaths save your pat.psd file on desktop, then close document. Open new one with any resolution and any (even unproportional to original) dimension. All subpaths sizes and positions will be adjusted to new document settings Can anyone to do the same with Action Manager only?

Ps. applied subpaths are deleted once after appearing. I did so as they won't be needed after later I finish script that makes stroke around them. After script completes its work, to see them all, browse history steps. For identical - original subpaths plotting remove Math.round (in line number seven of the script). Result will be very alike but performance a little slower.

(function(){function path(v) {

          for(var sP = v.slice(64).match(reg2), j = 0; j < sP.length; j++) {

               n = (isNaN(ch = sP[2].charCodeAt()) ? 0 : ch * 256) + sP[3].charCodeAt()

               for(var cor = sP.slice(26).match(/([^\n]|\n){26}/g), baf = [], k = 0; k < n; k++) {

                    baf = [[], [], []], vh = '', cor.slice(2).replace(/(([^\n]|\n){8})/g, function(v1, _, _, v2)

                         {for(l = 0; l < 8; l++) {(vh += (v1 ? ('0' + v1.charCodeAt().toString(16)).slice(-2) : '00' ))

                         if (l == 3 || l == 7) baf[v2 / 9][trn] = Math.round((num = eval('0x' + vh)) / Math.pow

                         (256, num > 4000000000 ? 6 : 3) * ((trn = +!baf[v2 / 9].length) ? hgt : wdt)), vh = ''}

                    })

               }

               function subPaths() {function lar(v) {function pos(v1, v2) {

                              (dsc5 = new ActionDescriptor()).putUnitDouble(sTT('horizontal'),

                              sTT('pixelsUnit' ), v1[0]), dsc5.putUnitDouble(sTT('vertical'),

                              sTT('pixelsUnit'), v1[1]), dsc4.putObject(sTT(v2), sTT('paint'), dsc5)

                         }

                         dsc4 = new ActionDescriptor(), pos(v[0], 'backward'), pos(v[1], 'anchor')

                         pos(v[2], 'forward'), lst3.putObject(sTT('null'), dsc4)

                    }

                    lst3 = new ActionList(); for(i = 0; i < baf.length; i++) lar(baf);

                    (dsc3 = new ActionDescriptor()).putBoolean(sTT('closedSubpath'), !sP[1].charCodeAt())

                    dsc3.putList(sTT('points'), lst3); (lst2 = new ActionList()).putObject(sTT('null'), dsc3);

                    (dsc2 = new ActionDescriptor()).putList(sTT('subpathListKey'), lst2); return dsc2

               }

               (ref1 = new ActionReference()).putProperty(sTT('path'), sTT('workPath'));

               (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);

               (lst1 = new ActionList()).putObject(sTT('pathComponent'), subPaths())

               dsc1.putList(sTT('to'), lst1), executeAction(sTT('set'), dsc1, DialogModes.NO)

          }

     }

     reg2 = /([^\n]|\n){4}(\x00){3}\x01(\x00){18}(\x00(\x01|\x02|\x04|\x05)([^\n]|\n){24})+/g

     reg1 = /\x06Path A.{57}(([^\n]|\n){26}(\x00(\x01|\x02|\x04|\x05)([^\n]|\n){24})+)+/g;

     (v = File('~/desktop/pat.psd')).open('r'), v.encoding = 'binary'; var arr = v.read()

     var arr = arr.slice(arr.indexOf('\x06Path A') - 1); var arr = arr.match(reg1); v.close()

     preferences.rulerUnits = Units.PIXELS, hgt = (aD = activeDocument).height

     wdt = aD.width; function sTT(v) {return stringIDToTypeID(v)} path(arr)

})()

Votes

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
People's Champ ,
Mar 05, 2018 Mar 05, 2018

Copy link to clipboard

Copied

You have a very strange way of writing code for scripts.
Even more strange is how they work for you.

Untitled-1.png

Votes

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
LEGEND ,
Mar 05, 2018 Mar 05, 2018

Copy link to clipboard

Copied

Yes sorry I edited code deleting for loop where i was defined. I did that as for now that loop wasn't needed for tests. Actually I tried a code before left changed and it worked. The matter of fact is that ExtendScript ToolKit has build-in? i variable that is set to zero for some reason. What's strange it works even ran from Photoshop (I mean that not defined i). Anyway like I say before some time after original posting I removed for loop it worked. To make it working for you and others please change at the end of code:

path(arr)

to

path(arr[0])

Votes

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
People's Champ ,
Mar 05, 2018 Mar 05, 2018

Copy link to clipboard

Copied

This can be if the variable is defined in some script in the folder

"C:/Program Files (x86)/Common Files/Adobe/Startup Scripts CS6/Adobe Photoshop"

Votes

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
LEGEND ,
Mar 05, 2018 Mar 05, 2018

Copy link to clipboard

Copied

I thought so too, but as I remember only twice I didn't difined i in my scripts on this forum. This time that was just mistake, I didn't notice it. Normally I care to do that. If script works for you and there is no problems I'm ready to write next part soon.

Votes

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
People's Champ ,
Mar 05, 2018 Mar 05, 2018

Copy link to clipboard

Copied

I created pat.psd with the size (1,072,940,028 bytes). Photoshop crashed.)

Votes

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
LEGEND ,
Mar 05, 2018 Mar 05, 2018

Copy link to clipboard

Copied

Thank for finding it. I created a file that in Windows Properties is seen with size: 1 102 518 918, but it's .psb, not .psd format. You were able to create so large .psd? It took some time Photoshop created it and another piece when I waited it finished saving it on disk. I ran then script for pat.psb that it took too long to wait to end. I reopened Photoshop and tried to open that big file I saved during previous session. Unfortunatelly I waited 2 minutes and couldn't even open a file that is so big (150000 px * 150000 px with 10000 px / in).

I did that to see is even sole Action Manager to read subpaths (not from binaries) from so big file, but as far as I could not open it, it seems maybe it could but had no chance to check it Well so there is problem with huge files, where it is no only about reading subpaths. I'm fine as it's exremal case, not regular bug, so after all thanks for letting me know about, I can make limitation for files with too high size to avoid this situation

I found that a half less file, that is still .psd can not be processed, it is not about script but opening a file that has to be read:

(v = File('~/desktop/pat.psd')).open('r'), v.encoding = 'binary'; var arr = v.read(); v.close()

It seems to be Photoshop bug? Do not you know is there any limit to store at once in variable large file binaries? Probably that can be done is to read characters / lines separately, making a loop over file binaries. When I replaced var arr = v.read() to var arr.readch() it worked. Unfortunately from past attempts I know that when some single line is too long then problem arises with readln() ie. script is reading such line at the moment. What is method to do it? Is there any way to see length of line to be read before that line is read to avoid a crash? I remember a month ago by a luck I could see your post where you explained to someone that he can increase Windows limit of read characters at once, maybe that could help. How to do it?

Votes

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
People's Champ ,
Mar 06, 2018 Mar 06, 2018

Copy link to clipboard

Copied

Unfortunately I have already deleted that file. But I now created the file 10000x10000x72, duplicated the white layer, applied the Noise filter (100%), duplicated the layer 5 times. The file was saved in incompatible mode (without composite data). The file took 1 726 668 650 bytes. It opens normally. All my scripts working with paths even with large number of points work instantly. If you run your script, Photoshop freezes. If the file has only three layers with noise, it takes 868 327 294 bytes and the photoshop is crased on the script

UPD. Why not use file.read(buffer_size) ?

Votes

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
LEGEND ,
Mar 06, 2018 Mar 06, 2018

Copy link to clipboard

Copied

Yes, I forgot again about parameter I can put into brackets. I wonder what is maxiumum number of chars there can be read by file.read(max). I will test that but maybe results will be different for different files, sometimes higher other time lower (or perhaps always same). If there was stable value for buffer to put into file.read() I could make a loop over another chunks of binaries. I hope there will not be problem. For ex. if last block (number of chars specified by buffer) will be certainly smaller than all previous even blocks then script might stop working as it won't recognize end of file.

These are my toughts, now it's time to see how that work.

Anyway if I will find in one of another chunks - 'paths' beginning part I can have problem to reach full length of paths data if continued part will go through next chunk(s). That'll need special method to obtain data of paths that can be extended into record of more than one chunk.

To ilustrate it here's very minimalized 'graphic' example for a file that is (proportionally) too big to read at once.

Let's assume there are 37 binary characters so I use file.read(10) as 11 is too big:

loop {

     1st iteration: 10 binary character

     2nd iteration: 10 binary characters // paths data starts at 8 character

     3rd iteration: 10 binary characters // paths data ends at 5 character

     4th iteration: 7 binary characters

}

but won't there be problem with 4th iteration while buffer is eqeul to 10 characters while chunk got 7? I will find it out

Votes

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
People's Champ ,
Mar 06, 2018 Mar 06, 2018

Copy link to clipboard

Copied

I do not know why you need it. But try this script. It finds all the paths even in a 1.6Gb file

var path_names = new Array();

var file= new File("F:\\TEST2\\1.psd"); // type your filepath

file.open("r");

file.encoding = "BINARY";

var bsize  = 10000;

var bsize2 = 10000;

var sign = "8BIM";

var pos = 0;

while(1)

    {

    file.seek(pos, 0);

    if (file.eof) break;

    var s = file.read(bsize);

    var i = s.indexOf(sign);

    if (i >= 0)

        {

        s = s + file.read(bsize2);

        var path_len = parse_path(s.substr(i), pos+i);

        if (path_len)

            pos = pos + i + path_len;

        else

            pos = pos + i + sign.length;

        }

    else

        {

        pos = pos + bsize - sign.length + 1;

        }

    }

var s = ""

for (var i = 0; i < path_names.length; i++)

    s += path_names[0] + " offset: 0x" + path_names[1].toString(16).toUpperCase()+"\n";

alert(s, "Path found")

function parse_path(s, pos)

    {

    var code = 256*s.charCodeAt(4) + s.charCodeAt(5)

    if (code >= 2000 && code <= 2997)

        {

        var l = s.charCodeAt(6);                   

        path_names.push([s.substr(7, l), pos]);

        return l+7;

        }

    if (code == 2999)

        {

        var l = s.charCodeAt(6);                   

        path_names.push(["Clipping Path", pos]);

        return l+7;

        }

    if (code == 1025)

        {

        path_names.push(["Working path (not saved)", pos]);

        return l+7;

        }

    return 0;

    }

P.S. I think that if after the found path the next signature is not the path, you can stop scaning.file )

Votes

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
LEGEND ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

LATEST

That's awsome you shared with me your version of doing the same, but for bigger files 😉

Votes

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
People's Champ ,
Mar 05, 2018 Mar 05, 2018

Copy link to clipboard

Copied

//For some reason, the message was not added. Repeat.

This can be if the variable is defined in some script in the folder

"C:/Program Files (x86)/Common Files/Adobe/Startup Scripts CS6/Adobe Photoshop"

Votes

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