我编写了一个脚本,该脚本可以选择多个路径,并重复它们,然后使用操作将“对象>信封变形>用顶部对象制作”应用到底部路径的每个副本以及选择中的所有其他路径(不要相信DOM中有任何可以直接与信封进行交互的内容)。所以我从这个开始:
https://i.stack.imgur.com/cBKZs.png
它在ExtendScript Toolkit中完美地工作,给了我这个:
https://i.stack.imgur.com/dLdRz.png
但是,如果我从Illustrator中执行脚本,则会遇到混乱:
https://i.stack.imgur.com/caL0u.png
这是我的代码:
var doc = app.activeDocument;
var sel = app.activeDocument.selection;
var currentLayer = app.activeDocument.activeLayer;
function envelope(){
var arr = [];
var bottomObject = sel[sel.length - 1];
bottomObject.selected = false;
for (i = 0; i < sel.length - 1; i++){
arr.push(sel[i]);
var newObjs = sel[i].duplicate();
newObjs.zOrder(ZOrderMethod.SENDBACKWARD)
}
currentLayer.hasSelectedArtwork = false;
for (i = 0; i < arr.length; i++){
var objectsToDistribute = bottomObject.duplicate();
objectsToDistribute.zOrder(ZOrderMethod.SENDTOBACK);
arr[i].selected = true;
objectsToDistribute.selected = true;
app.doScript('Envelope all', 'scriptTest');
}
}
envelope();
Here's操作集。那么,为什么我从同一个脚本中得到不同的结果呢?有没有办法从Illustrator中解决此问题?
答案 0 :(得分:0)
您必须将currentLayer.hasSelectedArtwork = false;
行移动到循环中。需要为每次迭代清除选择:
...
for (i = 0; i < arr.length; i++){
currentLayer.hasSelectedArtwork = false; // <------------- here
var objectsToDistribute = bottomObject.duplicate();
objectsToDistribute.zOrder(ZOrderMethod.SENDTOBACK);
arr[i].selected = true;
objectsToDistribute.selected = true;
app.doScript('Envelope all', 'scriptTest');
}
...
实际上,您不需要操作集。
可以通过app.executeMenuCommand('Make Envelope');
这是我的脚本版本:
var sel = app.activeDocument.selection; // all the objects that have been selected
var lowest = sel[sel.length-1]; // the lowest object
for (var i=0; i<sel.length-1; i++) {
var top = sel[i].duplicate(); // make a copy of the next object
var btm = lowest.duplicate(); // make a copy of the lowest object
app.selection = null; // deselect all
top.selected = true; // select the top copy
btm.selected = true; // select the bottom copy
app.executeMenuCommand('Make Envelope'); // make Envenlope
}
唯一的区别:它将转换所选对象中的最低对象。