【问题标题】:Joining intersecting paths in illustrator在 illustrator 中加入相交路径
【发布时间】:2020-01-27 21:44:56
【问题描述】:

短期问题:我在画板上有三个路径。一条路径的终点与另一条路径的起点在同一位置。另一条路径是分开的。它们都是分组的。我有一些代码循环遍历组中的路径,如果一条路径在另一条路径开始的地方结束,它会尝试将它们连接在一起。必须突出显示该组。从我的画板开始,看起来像这样(第一行是两条路径):

脚本运行后如下所示:

在下面的行尾添加了很多点。有人可以帮我看看吗,理想情况下,我希望它看起来像这样:

代码如下所示:

var doc = activeDocument;//Gets the active document
var numArtboards = doc.artboards.length;//returns the number of artboards in the document
var intersections = true
var group = doc.selection[0]
var paths = []
var intersecttions = 0

// Builds an array of all the paths in the grouped object
if (group !== undefined && group.pageItems.length >= 2) {
    for (var i = 0; i < group.pageItems.length; i++) {
        var item = group.pageItems[i];
        if (item instanceof PathItem) {
            item.id = 'Path No' + i;
            paths.push(item)
        }
    }
}

//Sets the first path that will be added to
$.write('paths length ', paths.length,'\n')
var chain = paths[0]
var chainPoints = chain.pathPoints
var chainLength = chainPoints.length - 1
var c1 = chainPoints[0]
var c2 = chainPoints[chainLength]
$.write('c ', c1.anchor,':::', c2.anchor,'\n')

//loops through the paths in the group to see if any overlap the first past
for (var i = 1; i < paths.length-1; i++) {
var link = paths[i]
$.write(link, '\n')
var linkPoints = link.pathPoints
var linkLength = linkPoints.length - 1
$.write('l ', l1.anchor, ':::', l2.anchor, '\n')

if (toString(c1.anchor) === toString(l2.anchor)) {
    $.write('inttersection', '\n')
    $.write('link', link.id, '\n')
    for (var j = 0; j < linkLength; ++j) {
        chain.pathPoints.add(linkPoints[j])
        $.write (linkPoints[j], '\n')
    }
}
}

【问题讨论】:

    标签: javascript adobe-illustrator extendscript


    【解决方案1】:

    第一个问题是它没有正确检测重叠实例。行:

    if (toString(c1.anchor) === toString(l2.anchor)) {
    

    不是将一个字符串与另一个字符串进行比较,而是将一个真实响应与另一个真实响应进行比较。应该是:

    if (String(c1.anchor) === String(l2.anchor)) {
    

    您还必须传递要添加到该行的每个点的属性并删除旧行,因此在 j 循环中您需要添加以下内容

    for (var j = 0; j < linkLength; ++j) {
            var pp1 = chainPoints.add()
            var p2i = linkPoints[j];
            pp1.anchor = p2i.anchor;
            pp1.rightDirection = p2i.rightDirection;
            pp1.leftDirection = p2i.leftDirection;
            pp1.pointType = p2i.pointType;
            pp1.handle = p2i.handle;
        }
    link.remove();
    

    这似乎有效,只是它没有添加第二行的最后一点。我猜循环长度可能设置不正确如果我解决了,我会更新帖子。我在 Hiroyuki Sato 的 JoinReasonable 脚本代码中发现了这一点http://shspage.com/aijs/en/

    【讨论】:

    • 将循环构造函数更改为以下应该可以修复此错误:var j = 0, jend = linkPoints.length; j
    猜你喜欢
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多