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

Add subpath to existing path

Community Beginner ,
Nov 21, 2017 Nov 21, 2017

Copy link to clipboard

Copied

I need to add a subpath to an existing path. The SubPathItems object doesn't provide the add method, so to add the subpath I create a new path that includes old subpaths and the new one, and then delete the old path. This causes flickering and doesn't look like the best solution.

Is there a better way to add a subpath to an existing path?

TOPICS
Actions and scripting

Views

896

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 , Nov 22, 2017 Nov 22, 2017

Try this method.

var subpath = example_subpath();

add_subpath(subpath);

////////////////////////////////////////////////////////////

function add_subpath(subpath_info)

    {

    try

        {

        var d = new ActionDescriptor();

        var r = new ActionReference();

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

        var path = executeActionGet(r).getObjectValue(stringIDToTypeID("pathContents"));          

        var list = path.getList(stringIDToT

...

Votes

Translate

Translate
Adobe
People's Champ ,
Nov 22, 2017 Nov 22, 2017

Copy link to clipboard

Copied

LATEST

Try this method.

var subpath = example_subpath();

add_subpath(subpath);

////////////////////////////////////////////////////////////

function add_subpath(subpath_info)

    {

    try

        {

        var d = new ActionDescriptor();

        var r = new ActionReference();

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

        var path = executeActionGet(r).getObjectValue(stringIDToTypeID("pathContents"));          

        var list = path.getList(stringIDToTypeID("pathComponents"));          

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

            list.putObject(stringIDToTypeID("null"), subpath_to_desc(subpath_info));

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

        d.putList(charIDToTypeID("T   "), list);

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

        return true;

        function subpath_to_desc(pth)

            {

            try

                {

                var op = stringIDToTypeID("xor");

                try {       

                    switch (pth.operation)

                        {

                        case ShapeOperation.SHAPEADD      : op = stringIDToTypeID("add");       break;

                        case ShapeOperation.SHAPEINTERSECT: op = stringIDToTypeID("subtract");  break;

                        case ShapeOperation.SHAPESUBTRACT : op = stringIDToTypeID("intersect"); break;

                        case ShapeOperation.SHAPEXOR      : op = stringIDToTypeID("xor");       break;

                        }

                    }

                catch(e) {}

       

                var d = new ActionDescriptor();

       

                var subpathlist = new ActionList();             

       

                var d1 = new ActionDescriptor();

       

                try { d1.putBoolean(stringIDToTypeID("closedSubpath"), pth.closed); } catch(e) {}

       

                var points = new ActionList();             

       

                var pp = pth.entireSubPath;

       

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

                    {

                    var d2 = new ActionDescriptor();

                    var anchor = new ActionDescriptor();

                    anchor.putUnitDouble( stringIDToTypeID("horizontal"), charIDToTypeID( "#Rlt" ), pp.anchor[0]);

                    anchor.putUnitDouble( stringIDToTypeID("vertical"),   charIDToTypeID( "#Rlt" ), pp.anchor[1]);

                    d2.putObject(stringIDToTypeID("anchor"),   stringIDToTypeID("paint"), anchor);

       

                    try {       

                        var forward = new ActionDescriptor();

                        forward.putUnitDouble( stringIDToTypeID("horizontal"), charIDToTypeID( "#Rlt" ), pp.leftDirection[0]);

                        forward.putUnitDouble( stringIDToTypeID("vertical"),   charIDToTypeID( "#Rlt" ), pp.leftDirection[1]);

                        d2.putObject(stringIDToTypeID("forward"),  stringIDToTypeID("paint"), forward);

                        }

                    catch(e) {}

       

                    try {       

                        var backward = new ActionDescriptor();

                        backward.putUnitDouble( stringIDToTypeID("horizontal"), charIDToTypeID( "#Rlt" ), pp.rightDirection[0]);

                        backward.putUnitDouble( stringIDToTypeID("vertical"),   charIDToTypeID( "#Rlt" ), pp.rightDirection[1]);

                        d2.putObject(stringIDToTypeID("backward"), stringIDToTypeID("paint"), backward);

                        }

                    catch(e) {}

       

                    try {       

                        d2.putBoolean(stringIDToTypeID("smooth"), pp.kind==PointKind.SMOOTHPOINT?true:false);

                        }

                    catch(e) {}

       

                    points.putObject(stringIDToTypeID("null"), d2)

                    }

       

                d1.putList(stringIDToTypeID("points"), points)

                subpathlist.putObject(stringIDToTypeID("null"), d1)

                d.putEnumerated(stringIDToTypeID("shapeOperation"), stringIDToTypeID("shapeOperation"), op );

                d.putList(stringIDToTypeID("subpathListKey"), subpathlist);

       

                return d;

                }

            catch (e) { alert(e); return null; }

            }

        }

    catch (e) { alert(e); return false; }

    }

////////////////////////////////////////////////////////////

function example_subpath()

    {

    var pth = new Array();

    var p = new Array();

    p[0] = new PathPointInfo;  

    p[0].kind = PointKind.CORNERPOINT; 

    p[0].anchor = [100, 10];

    p[0].leftDirection  = p[0].anchor;

    p[0].rightDirection = p[0].anchor;

    p[1] = new PathPointInfo;  

    p[1].kind = PointKind.CORNERPOINT; 

    p[1].anchor = [150, 60]

    p[1].leftDirection  = p[1].anchor;

    p[1].rightDirection = p[1].anchor;

    p[2] = new PathPointInfo;  

    p[2].anchor = [50, 60];

    pth[0] = new SubPathInfo();

    pth[0].operation = ShapeOperation.SHAPEADD;

    pth[0].closed = true;

    pth[0].entireSubPath = p;

    return  pth;

    }

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