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

Photoshop Script to continue work path

Engaged ,
Dec 09, 2018 Dec 09, 2018

Copy link to clipboard

Copied

Hello everyone,

I opened a document that already had a path, and then I select the path from the "Paths" window:

1.JPG

2.JPG

and it is shown on the canvas:

3.JPG

I want a script that will continue the current path so I can close the path. (sometimes the path will be somewhere else so I can't rely on exact X,Y position)
I want something like this for example:

4.JPG

that's it.

TOPICS
Actions and scripting

Views

2.8K

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

People's Champ , Dec 10, 2018 Dec 10, 2018

Try this. Works in CC2018. In CS6 does not work.

var len = app.activeDocument.pathItems.length;

if (len)

    {

    var pth = app.activeDocument.pathItems[len-1];

    pth.deselect();

    pth.select();

    len = pth.subPathItems.length;

    var p = pth.subPathItems[len-1].pathPoints[pth.subPathItems[len-1].pathPoints.length-1];

    var zoom = get_doc_zoom();

    set_doc_zoom(100);

    pen(p.anchor[0], p.anchor[1]);

    set_doc_zoom(zoom);

    }

else

    alert("No path");   

function pen(x, y)

    {

    var d = n

...

Votes

Translate

Translate
Adobe
People's Champ ,
Dec 09, 2018 Dec 09, 2018

Copy link to clipboard

Copied

Do you want to activate (select) the last point in the Path?

If so, then I tried to do this in CS6 using the code obtained from the record of the PathSelectionTool action. It works extremely unreliable and I abandoned this idea.

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

Copy link to clipboard

Copied

But it should be possible to auto-complete the open subPathItem if there are clear and unequivocal rules about how it is to be completed.

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
Engaged ,
Dec 10, 2018 Dec 10, 2018

Copy link to clipboard

Copied

r-bin​, c.pfaffenbichler​ thank you for your replies. I'm on the way to solve it, I made a new path, and recorded the last anchor point in an action, I played the action afterwards and it said "Pick-up Path"

I think I have 2 ways to go from here (i need help to execute each one of them since I don't know how)

1. find a script to "Pick-up Path"

2. I've recorded the last anchor point in an action, if I could record the last anchor point and somehow save it for later, for example: write the X,Y position into the Metadata and later delete it, it should work, only question how I record the anchor point or the last anchor point

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

Copy link to clipboard

Copied

Try this. Works in CC2018. In CS6 does not work.

var len = app.activeDocument.pathItems.length;

if (len)

    {

    var pth = app.activeDocument.pathItems[len-1];

    pth.deselect();

    pth.select();

    len = pth.subPathItems.length;

    var p = pth.subPathItems[len-1].pathPoints[pth.subPathItems[len-1].pathPoints.length-1];

    var zoom = get_doc_zoom();

    set_doc_zoom(100);

    pen(p.anchor[0], p.anchor[1]);

    set_doc_zoom(zoom);

    }

else

    alert("No path");   

function pen(x, y)

    {

    var d = new ActionDescriptor();

    var r = new ActionReference();

    r.putClass(stringIDToTypeID("penTool"));

    d.putReference(charIDToTypeID('null'), r);

    var data = String.fromCharCode(

        0x00,0x00,0x00,0x06,0x02,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x08,0x54,0x50,0x65,0x6E,0x54,0x6F,0x6F,0x6C,0x00,0x00,0x00,0x08,0x54,0x50,0x65,0x6E,0x54,0x6F,0x6F,

        0x6C,0x00,0x00,0x00,0x08,0x54,0x50,0x65,0x6E,0x54,0x6F,0x6F,0x6C,0x00,0x00,0x00,0x06,0x3C,0x4E,0x55,0x4C,0x4C,0x3E,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,

        0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00) +

        toIEEE754(x, 8, 23) + toIEEE754(y, 8, 23) +

        String.fromCharCode(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00) +

        toIEEE754(x, 8, 23) + toIEEE754(y, 8, 23) +

        String.fromCharCode(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);

    d.putData(stringIDToTypeID("toolRecordingData"), data);

    executeAction(stringIDToTypeID('toolRecording'), d, DialogModes.NO);

    };

function set_doc_zoom(zoom) 

    { 

    try { 

        if (!zoom) zoom = 100; 

 

        var d = new ActionDescriptor();   

        var r = new ActionReference();   

        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("zoom"));   

        r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));   

        d.putReference(stringIDToTypeID("null"), r);   

 

        var d1 = new ActionDescriptor();   

        d1.putUnitDouble(stringIDToTypeID("zoom"), stringIDToTypeID("pixelsUnit"), zoom/100);

        d.putObject(stringIDToTypeID("to"), stringIDToTypeID("zoom"), d1);   

        executeAction(stringIDToTypeID("set"), d, DialogModes.NO);   

        } 

    catch (e) { /*throw(e);*/ } 

    } 

function get_doc_zoom() 

    { 

    try { 

        var r = new ActionReference();   

        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("zoom"));   

        r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));   

        return executeActionGet(r).getUnitDoubleValue(stringIDToTypeID("zoom"))*100;

        } 

    catch (e) { throw(e); } 

    } 

function toIEEE754(v, ebits, fbits)

    {

    try {

        var bias = (1 << (ebits - 1)) - 1;

   

        var s, e, f;

        if (isNaN(v))

            {

            e = (1 << bias) - 1; f = 1; s = 0;

            }

        else if (v === Infinity || v === -Infinity)

            {

            e = (1 << bias) - 1; f = 0; s = (v < 0) ? 1 : 0;

            }

        else if (v === 0)

            {

            e = 0; f = 0; s = (1 / v === -Infinity) ? 1 : 0;

            }

        else

            {

            s = v < 0;

            v = Math.abs(v);

   

            if (v >= Math.pow(2, 1 - bias))

                {

                var ln = Math.min(Math.floor(Math.log(v) / Math.LN2), bias);

                e = ln + bias;

                f = v * Math.pow(2, fbits - ln) - Math.pow(2, fbits);

                }

            else

                {

                e = 0;

                f = v / Math.pow(2, 1 - bias - fbits);

                }

            }

        

        var i, bits = [];

        for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = Math.floor(f / 2); }

        for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = Math.floor(e / 2); }

        bits.push(s ? 1 : 0);

        bits.reverse();

        var str = bits.join('');

        

        var bytes = "";

        while (str.length)

            {

            bytes += String.fromCharCode(parseInt(str.substring(0, 8), 2));

            str = str.substring(8);

            }

        return bytes;

        }

    catch (e) { throw(e); } 

    }

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
Engaged ,
Dec 10, 2018 Dec 10, 2018

Copy link to clipboard

Copied

Works!

(Photoshop CC 2019)

Thanks!!

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

Copy link to clipboard

Copied

There is a bug.

It works correctly only if

app.preferences.rulerUnits = Units.PIXELS;

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
Engaged ,
Dec 10, 2018 Dec 10, 2018

Copy link to clipboard

Copied

I use pixels as units anyway, but i'll add this to the beginning of the script anyway

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
Enthusiast ,
Dec 12, 2018 Dec 12, 2018

Copy link to clipboard

Copied

LATEST

Hi, I find it useful.

Still, there is a big issue I think it is a big limitation.

If we have several subPathItems in a single Path, there is no way on getting the one that it is selected.

So, in the end, it only selects always the last subPathItem (or the one on top of all).

This has the potential to be a great addition tool and I think it could be avoided so, so many zoomOut/zoomIn on the complex path creation.

There should exist something like

app.activeDocument.activePathItem.activeSubPathItem

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