0
点赞
收藏
分享

微信扫一扫

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

zhyuzh3d 2022-02-16 阅读 64

  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;
}

  合理的脚本代码可以有效的提高工作效率,减少重复劳动。


  欢迎光临知了软件开发网络平台,本公司定制开发各类软件,主要方向为桌面专业软件开发和插件定制开发,桌面软件主要包括文字图形识别类软件,信息管理类软件,3D打印类软件,视频类软件以及其它涉及专业的各类图形图像处理软件。插件包含AE插件,AI插件,PS插件,PDF插件,3DMAX插件以及Word,Excel等Office插件开发。详情请咨询,微信QQ:312117271,手机:18928899728.
公司网址:http://www.zhiliaos.com

举报

相关推荐

0 条评论