萬盛學電腦網

 萬盛學電腦網 >> 圖文處理 >> Adobe Illustrator教程 >> AI腳本添加當前高光和陰影到色板

AI腳本添加當前高光和陰影到色板

這篇教程教的朋友們用AI腳本添加當前高光和陰影到色板,教程主要介紹一下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 ( [email protected] ) 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;
   }
}

copyright © 萬盛學電腦網 all rights reserved