-1

I am working to build a color swatch book. I am starting with just CMYK first and will move into other areas with this format once I get this established first. I have been able to develop all the containers needed, but I am unable to add a fillColor to these boxes. I feel that I do not know how to do this. Can someone please give me some help? Below is my script. Please keep in mind that my CMYK values must be able to be input as variable ex.

Var c = 0

Var m = 0

Var y = 0

Var k = 0

when I run this through a loop I will increase it by 5% so, it would be c=c+5 and then it will iterate through my loop.

    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

    }
John D
  • 139
  • 13

3 Answers3

2

You have to create and apply swatches to your rectangles:

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; 

This is based on Kasyan Servetsky reply to this thread https://forums.adobe.com/thread/942867

Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23
0

a rectangle object has a fillColor property:

myRectangle.fillColor[5,5,5,5];
Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23
  • I just tried this line of script and it goes into debug mode and errors on this line. I agree that a rectangle has this color property, but I don't think this is how its used and from what I have seen you need to call it out as a string – John D Aug 29 '17 at 13:40
  • 1
    You are right, it needs a swatch. See my other answer – Nicolai Kant Aug 29 '17 at 14:18
0

some remarks:

  • according to ID Obj Model object.geometricBounds coordinates orders is y1,x1,y2,x2 --> where 'y' is vertical and 'x' horizontal; '1' UpLeft, '2' RightDown;

  • did you consider count of colors to be created assuming increasing step = 5?

Test below example code:

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
        });
}
Cashmirek
  • 269
  • 1
  • 9