illustrator插件-常用功能开发-锚点分隔路径-js脚本开发-AI插件

1.算法程序

  illustrator是矢量编辑软件,画板是绘制处理的重要容器,在印刷方面的一个重要功能就是锚点分隔路径,开发一个锚点分隔路径功能,以下功能仅用于学习交流,请勿用于非法用途和商业用途,源代码如下所示:

var PMSLibs = confirm("选择路径后使用此脚本,会按照所选路径的锚点分隔路径\n分隔路径数=全部锚点-1\n\n插件定制,手机微信:18928899728");

main();
function main()
{
    var sp = [];
    getPathItemsInSelection(2, sp);
    if (sp.length < 1)
        return;

    var j,k,p;
    var first_anchor_selected,idxs,ary,ancs;

    for (var i = 0; i < sp.length; i++)
    {
        p = sp[i].pathPoints;
        idxs = [[0]];
        first_anchor_selected = isSelected(p[0]);

        for (j = 1; j < p.length; j++)
        {
            idxs[idxs.length - 1].push(j);
            if (isSelected(p[j]))
                idxs.push([j]);
        }
        if (idxs.length < 2 && !(first_anchor_selected && sp[i].closed))
            continue;

        // adjust the array (closed path)
        if (sp[i].closed)
        {
            if (first_anchor_selected)
            {
                idxs[idxs.length - 1].push(0);
            }
            else
            {
                ary = idxs.shift();
                idxs[idxs.length - 1] = idxs[idxs.length - 1].concat(ary);
            }
        }

        // duplicate the path and apply the data of the array
        for (j = 0; j < idxs.length; j++)
        {
            ary = idxs[j];
            ancs = [];

            for (k = ary.length - 1; k >= 0; k--)
                ancs.unshift(p[ary[k]].anchor);

            with (sp[i].duplicate())
            {
                closed = false;
                setEntirePath(ancs);

                for (k = pathPoints.length - 1; k >= 0; k--)
                {
                    with (pathPoints[k])
                    {
                        rightDirection = p[ary[k]].rightDirection;
                        leftDirection = p[ary[k]].leftDirection;
                        pointType = p[ary[k]].pointType;
                    }
                }
            }
        }
        sp[i].remove(); // remove the original path
    }
}

// ------------------------------------------------
// extract PathItems from the selection which length of PathPoints
// is greater than "n"
function getPathItemsInSelection(n, pathes)
{
    if (documents.length < 1)
        return;

    var s = activeDocument.selection;

    if (!(s instanceof Array) || s.length < 1)
        return;

    extractPathes(s, n, pathes);
}

// --------------------------------------
// extract PathItems from "s" (Array of PageItems -- ex. selection),
// and put them into an Array "pathes".  If "pp_length_limit" is specified,
// this function extracts PathItems which PathPoints length is greater
// than this number.
function extractPathes(s, pp_length_limit, pathes)
{
    for (var i = 0; i < s.length; i++)
    {
        if (s[i].typename == "PathItem"
             && !s[i].guides && !s[i].clipping)
        {
            if (pp_length_limit
                 && s[i].pathPoints.length <= pp_length_limit)
            {
                continue;
            }
            pathes.push(s[i]);

        }
        else if (s[i].typename == "GroupItem")
        {
            // search for PathItems in GroupItem, recursively
            extractPathes(s[i].pageItems, pp_length_limit, pathes);

        }
        else if (s[i].typename == "CompoundPathItem")
        {
            // searches for pathitems in CompoundPathItem, recursively
            // ( ### Grouped PathItems in CompoundPathItem are ignored ### )
            extractPathes(s[i].pathItems, pp_length_limit, pathes);
        }
    }
}

// --------------------------------------
function isSelected(p)
{
    return p.selected == PathPointSelection.ANCHORPOINT;
}

2.作者答疑


  如有疑问,请留言。

提示: 作者知了-联系方式1
提示: 作者知了-联系方式2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值