Skip to main content
Participant
October 21, 2008
Question

Changing CMYK values of existing colour

  • October 21, 2008
  • 7 replies
  • 496 views
I want to change the CMYK values of a colour. I have tried the following but with no success. Does anyone know what I am doing wrong? The property 'colorValue[ ]' should be R/W; I can read OK but cannot change the colour.

app.activeDocument.colors[11].colorValue[0] = 9.0;
app.activeDocument.colors[11].colorValue[1] = 10.0;
app.activeDocument.colors[11].colorValue[2] = 11.0;
app.activeDocument.colors[11].colorValue[3] = 12.0;
This topic has been closed for replies.

7 replies

Known Participant
October 22, 2008
That explains why it didn't work when I tried that, thanks a bunch.

Brett
Inspiring
October 22, 2008
Brett,

You can change the value of an item in an array. Which is what you've done. Arrays would be pretty useless otherwise.

What you can't do is directly change the value of an array that is a property of an object. If you had written:

myAFrame.geometricBounds[2] += 1;

it would not have worked.

Dave
Known Participant
October 22, 2008
Hi Dave,

So given you can't write to a single value in an array, why does the following snippet work for me?

var myDoc = app.activeDocument;
var pageTwo = myDoc.pages.item(1);
var myAF = pageTwo.textFrames.item("addFrame");
var myAFrame = myAF;
var myTextFrameSize = myAFrame.geometricBounds;
while (myAF.overflows == true) {
myTextFrameSize[2] = myTextFrameSize[2] + 1; // increases the bottom of the frame '[2]' by a value of 1 until there is no overflow.
myAFrame.geometricBounds = myTextFrameSize;
}

Is it because I am assigning it with a variable or was it just blind luck that I managed to get this working? I think most of my scripts may fall into the latter category...:-)

Brett
Participant
October 22, 2008
Thanks Dave.

I'm a happy script monkey again. :-)
Inspiring
October 21, 2008
If a property is an array, then you must set it using an array. You can read the individual members of the array, but you can't write them.

The reason you don't get a runtime error is because the ExtendScript engine creates a temporary copy of the array when you attempt to address it and then it changes the item in that array that you attempt to address. So, the code "works" but it just doesn't do what you want it to do.

Dave
Jongware
Community Expert
Community Expert
October 21, 2008
Dave,

How do you know which elements can be set one at a time and which
i must
be set using an array?

The other day I wrote a quicky and got bitten (again!) by geometricBounds.
Inspiring
October 21, 2008
It is read/write, but you have to write the whole array at once:

app.activeDocument.colors[11].colorValue = [9.0, 10.0, 11.0, 12.0];

Dave