这篇教程教的朋友们用AI脚本添加当前高光和阴影到色板,教程主要介绍一下AI的脚本使用技巧。转发过来和飞特的AI爱好者们一起学习这个方法。
该脚本会将当前的填色及其高光和阴影添加到色板之中。
默认RGB高光所有值+35、阴影-35;CMYK高光所有值-18%、阴影+10%。
如果选择的是一个专色,那么该颜色会被转换到当前文档的颜色空间中。
只能对一个纯色填充的对象执行该脚本,选择渐变、网格或是多个对象时均会报错!
要用“文件-脚本”来使用,以CS3为例应放在"C:Program FilesAdobeAdobe Illustrator CS3预设脚本"下。
当然,也可以放置在其他文件夹中,通过Ctrl+F12定位到脚本所在处来使用。
复制以下全部文字到记事本中,保存为以.js结尾的脚本文件(如:脚本.js)即可。
/////////////////////////////////////////////////////////////////
//Add Highlight And Shadow Swatches v.1 -- CS, CS2
//>=--------------------------------------
// A simple script for Animators. Takes current fill color from color pallate.
// a prompt will ask you to name the color, then it adds it to the swatch palate,
// along with the highlight and shadow for that color.
//
// feel free to tweak the values to get whatever percentages work best for you.
//
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////
//specified value greater than maximum allowed value(指定的值超出最大范围)
var docRef= app.activeDocument;
if ( app.documents.length > 0 )
{
//在这设置RGB高光、阴影参数
RGBdarkenBy = -35;
RGBlightenBy = 75;
//在这设置CMYK高光、阴影参数
CMYKdarkenBy = 10;
CMYKlightenBy = -18;
defName = "";
nameMsg = "该填充色及其高光和阴影将被添加到色板中。默认RGB高光所有值+35、阴影-35;CMYK高光所有值-18%、阴影+10%。现在请为该填充色命名:";
//获取颜色空间名称
t=[];
t = ((activeDocument.documentColorSpace)+"").split(".")
colSpace = t[1];
try{
var fill = docRef.defaultFillColor;
if(docRef.defaultFilled == false){
throw ("抱歉,没有找到填充色,请重新选择。");
}
if (fill.typename != "SpotColor" && fill.typename != "RGBColor" && fill.typename != "CMYKColor")
{
hrow("Sorry, "+fill.typename+" Objects are not currently supported.nPlease convert the color to "+colSpace+".");
}
if(fill.typename == "SpotColor"){
nameMsg += "■警告■你选择了一个专色,该颜色会被转换到当前文档的颜色空间中。";
fill = docRef.defaultFillColor.spot.color;
defName = colSpace+"("+docRef.defaultFillColor.spot.name+")";
}
if(fill.typename == "RGBColor"){
fr = roundHack(fill.red);
fg = roundHack(fill.green);
fb = roundHack(fill.blue);
if (defName.length <1 )
{
defName = "r="+ fr+" g="+fg + " b="+fb;
}
colName = getName();
//在这里添加RGB颜色参数:
makeColor([fr,fg,fb],RGBlightenBy,colName+" 的高光");
makeColor([fr,fg,fb],0,colName);
makeColor([fr,fg,fb],RGBdarkenBy,colName+" 的阴影");
} else if(fill.typename == "CMYKColor"){
fc = roundHack(fill.cyan);
fm = roundHack(fill.magenta);
fy = roundHack(fill.yellow);
fk = roundHack(fill.black);
if (defName.length <1)
{
defName = "c="+ fc+" m="+fm + " y="+fy+ " k="+fk;
}
colName = getName();
//在这里添加CMYK颜色参数:
makeColor([fc,fm,fy,fk],CMYKlightenBy,colName+" 的高光");
makeColor([fc,fm,fy,fk],0,colName);
makeColor([fc,fm,fy,fk],CMYKdarkenBy,colName+" 的阴影");
}
}
catch(e) {
alert("请确认:n"+e);
}
}
function getName(){
x = prompt(nameMsg,defName);
if (x == null)
{
throw "操作被取消!";
}
return x;
}
function makeColor(arr,offset,cname){
for (each in arr)
{
arr[each] = parseInt(arr[each]);
arr[each] += offset;
}
if(arr.length == 3){
//RGB
var nc = new RGBColor();
nc.red = limit(arr[0],255);
nc.green = limit(arr[1],255);
nc.blue = limit(arr[2],255);
} else if (arr.length == 4){
//CMYK
var nc = new CMYKColor();
nc.cyan = limit(arr[0],100);
nc.magenta = limit(arr[1],100);
nc.yellow = limit(arr[2],100);
nc.black = limit(arr[3],100);
}
var col = docRef.swatches.add();
col.name = cname;
col.color = nc;
}
function roundHack(n){
//make it a string
n = n +"" ;
ta = [];
ta = n.split(".");
return ta[0];
}
function limit(num,max){
if (num <= 0)
{
return 0;
}
else if(num > max )
{
return max;
}
else {
return num;
}
}