如何使用CMYK Build的步长增量将颜色构建添加到新矩形

时间:2017-08-28 16:26:06

标签: javascript adobe-indesign

我正在制作一本色板书。我首先从CMYK开始,一旦我首先建立这个格式,将以这种格式进入其他领域。我已经能够开发所需的所有容器,但我无法在这些盒子中添加fillColor。我觉得我不知道该怎么做。有人可以帮我一下吗?下面是我的脚本。请记住,我的CMYK值必须能够作为变量输入

Var c = 0

Var m = 0

Var y = 0

Var 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

    }

3 个答案:

答案 0 :(得分:0)

矩形对象有一个fillColor属性:

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

答案 1 :(得分: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

答案 2 :(得分:0)

一些评论:

  • 根据ID Obj Model object.geometricBounds坐标顺序为y1,x1,y2,x2 - &gt;其中'y'是垂直的,'x'是水平的; '1'UpLeft,'2'LightDown;

  • 你是否考虑过假设增加步数= 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
        });
}