将颜色构建添加到新的矩形,但在InDesign脚本中添加CMYK变量

问题描述:

我正在努力构建颜色色板书。我首先从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 

    } 

一个矩形对象有一个FillColor属性:

myRectangle.fillColor[5,5,5,5]; 
+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

一些备注:

  • 根据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 
     }); 
}