2017-08-28 61 views
-1

我正在努力構建顏色色板書。我首先從CMYK開始,一旦我首先確定這個格式,就會進入其他領域。我已經能夠開發所有需要的容器,但是我無法將fillColor添加到這些框中。我覺得我不知道該怎麼做。有人可以給我一些幫助嗎?以下是我的腳本。請記住,我的CMYK值必須能夠作爲變量ex輸入。將顏色構建添加到新的矩形,但在InDesign腳本中添加CMYK變量

瓦爾C = 0

瓦爾m = 0的

瓦爾y = 0的

瓦爾K = 0

當我通過一個循環運行此我會增加5%其所以,它會是c = c + 5,然後它會遍歷我的循環。

myDocument = app.activeDocument; 



{//Create a layer to hold the printers marks (if it does not already exist). 

var myLayer = myDocument.layers.item("ColorSwatches"); 

try{ 

    myLayerName = myLayer.name; 

} 

catch (myError){ 

    var myLayer = myDocument.layers.add({name:"ColorSwatches"}); 

} 

    } 

    //Create Rectangle 

    //Set the bounds of the rectangle [x1, y1, x2, y2] 

    //The x1, y1 refers to the upper left coordinate position; the x2, y2 refers to the lower right coordinate 

    //x2 = Height and y2 = Width 

    var myPage = myDocument.pages.item(0); 

    var y1=1.76 

    var y2=2.21 

    var x1=1.05 

    var x2=1.5 

    for (i = 0; i<105; i=i+5) { 

    for (m=0;m<105;m=m+5){ 

    var myRectangle = myPage.rectangles.add({geometricBounds:[x1, y1, x2, y2]}); 



    y1=y1+.50 

    y2=y2+.50 

    } 

    y1=1.76 

    y2=2.21 

    x1=x1+.50 

    x2=x2+.50 

    } 

回答

0

一個矩形對象有一個FillColor屬性:

myRectangle.fillColor[5,5,5,5]; 
+0

我只是想這行腳本,並進入調試模式和錯誤在這條線。我同意一個矩形具有這種顏色屬性,但我不認爲這是它的使用方式,從我所看到的你需要將它稱爲字符串 –

+0

你是對的,它需要一個色板。看到我的其他答案 –

0

你必須創建和應用色板的矩形:

var myDoc = app.documents[0]; 
var myRectangle = myDoc.rectangles[0]; 
var myColor = myDoc.colors.add(); 
myColor.colorValue = [5,5,5,5]; 
myColor.name = "My New Color"; 
myRectangle.fillColor = myColor; 

這是基於Kasyan Servetsky回覆此線程https://forums.adobe.com/thread/942867

0

一些備註:

  • 根據ID的OBJ模型object.geometricBounds座標訂單

    是Y1,X1,Y2,X2 - >其中, 'y' 爲垂直和 'X' 是水平的; '1'UpLeft,'2'RightDown;

  • 您是否考慮過在增加step = 5的情況下創建顏色計數?

測試下面的示例代碼:

const 
myDocument = app.activeDocument, 
myPage = myDocument.pages[0], 
recLimit = 441,     // count of rectangles to be created 
colorValueJumper = 5, 
boxSide = Math.floor(Math.sqrt(recLimit)), 
pageWidth = myPage.bounds[3] - myPage.bounds[1], 
squareSize = Math.floor(pageWidth/boxSide); 
var 
myLayer = myDocument.layers.item("ColorSwatches"), 
step = 0, 
c, m, y, k, currentColor; 

if(!myLayer.isValid) myLayer = myDocument.layers.add({name:"ColorSwatches"}); 

for(k = 0; k<=100; k = k+colorValueJumper) 
    for(y = 0; y<=100; y = y+colorValueJumper) 
     for(m = 0; m<=100; m = m+colorValueJumper) 
      for(c = 0; c<=100; c = c+colorValueJumper) { 
       if (++step == recLimit) exit(); 
       currentColor = myDocument.colors.add({ 
        model: ColorModel.PROCESS, 
        space: ColorSpace.CMYK, 
        colorValue: [c,m,y,k], 
        name: ("00000" + step).slice(-5) + "_CMYK: " + [c,m,y,k].join(" - ") 
        }); 
       createRec(step, currentColor); 
       } 
function createRec(cnt, cColor) { 
var 
    y0 = cnt%boxSide*squareSize, 
    x0 = Math.floor(cnt/boxSide)*squareSize, 
    y1 = (cnt%boxSide + 1)*squareSize, 
    x1 = (Math.floor(cnt/boxSide) + 1)*squareSize, 
    mRec = myPage.rectangles.add({ 
     geometricBounds: [y0,x0,y1,x1], 
     itemLayer: myLayer, 
     fillColor: cColor 
     }); 
}