我正在为Illustrator中的活动文档编写脚本。活动文档中已经有了“铅”的专色样例。所有我必须设置的路径和符号都需要设置到这个样例中。我已经通过删除样例然后将其重新添加到文档中的方式解决了这个问题。这适用于我创建的所有路径和对象。活动文档中有3个元件由脚本放置,并且已设置为专色样例。当我的脚本删除样例时,它会将符号重置为100%黑色进程。有没有办法从激活的文档中拉出色板?所有的路径项都需要leadSpotColor变量来设置颜色。在活动文档中已存在引线样本。如果我没有在递手前添加样例删除行,它就会出错,但样例删除行将活动文档中已有的符号设置为100%处理黑色,并且它们还需要设置为引线样例。
if ( app.documents.length = "LEAD" ) {
swatchToDelete = app.activeDocument.swatches["LEAD"];
swatchToDelete.remove();
}
var leadSpot = doc.spots.add();
var leadSpotColor = new CMYKColor();
leadSpotColor.cyan = 0;
leadSpotColor.magenta = 0;
leadSpotColor.yellow = 0;
leadSpotColor.black = 100;
leadSpot.name = "LEAD";
leadSpot.colorType = ColorModel.SPOT;
leadSpot.color = leadSpotColor;
var leadSpotColor = new SpotColor();
leadSpotColor.spot = leadSpot;发布于 2016-02-05 22:06:23
如果可以编辑样例,为什么要删除它?
var main = function(){
var doc,
leadClr, c;
if(!app.documents.length) return;
doc = app.activeDocument;
leadClr = getLeadColor(doc);
if ( leadClr===null ) {
var leadSpot = doc.spots.add();
var leadSpotColor = new CMYKColor();
leadSpotColor.cyan = 0;
leadSpotColor.magenta = 0;
leadSpotColor.yellow = 0;
leadSpotColor.black = 100;
leadSpot.name = "LEAD";
leadSpot.colorType = ColorModel.SPOT;
leadSpot.color = leadSpotColor;
var leadSpotColor = new SpotColor();
leadSpotColor.spot = leadSpot;
}
else {
c = leadClr.color.spot.color;
c.cyan = 0;
c.magenta = 0;
c.yellow = 0;
c.black = 100;
}
};
var getLeadColor = function(doc){
var clrs = doc.swatches,
n = clrs.length;
while (n-- ) {
if ( clrs[n].name=="LEAD" ) return clrs[n];
}
return null;
}
main();
我建议添加一些预防机制,比如确保样本实际上是到达斑点属性之前的斑点。
发布于 2017-09-09 23:12:32
首先,代码的第一行是错误的
if ( app.documents.length = "LEAD" )如何将长度与字符串"LEAD“进行比较,它应该是一个数字,而且在if语句中,我们使用条件运算符,您正在做的是在if语句中赋值。
这是铅专色的脚本,它将给你提供专色,如果存在,否则它将创建新的专色与名称“铅”
function main() {
var currentDocument;
var leadSpotColor;
if (!app.documents.length) {
alert("No document is open");
return;
}
currentDocument = app.activeDocument;
leadSpotColor = getLeadSpotColor(currentDocument);
applyColorToAllPath(leadSpotColor, currentDocument);
}
function getLeadSpotColor(currentDocument) {
try {
var leadSpotColor = currentDocument.spots.getByName('LEAD')
return leadSpotColor;
} catch (e) {
var color = new CMYKColor();
color.cyan = 0;
color.magenta = 0;
color.yellow = 0;
color.black = 100;
var newSpot = currentDocument.spots.add();
newSpot.name = "LEAD";
newSpot.colorType = ColorModel.SPOT;
newSpot.color = color;
var leadSpotColor = new SpotColor();
leadSpotColor.spot = newSpot;
return leadSpotColor;
}
}
function applyColorToAllPath(leadSpotColor, currentDocument) {
// Change code as per your requiremnt. I just handled for pathItems. You can similary for symbols.
var pathItems = currentDocument.pathItems;
for (var i = 0; i < pathItems.length; i++) {
pathItems[i].filled = true;
pathItems[i].fillColor = leadSpotColor;
pathItems[i].stroke = true;
pathItems[i].strokeColor = leadSpotColor;
}
}
main();https://stackoverflow.com/questions/34959547
复制相似问题