Hi @mateuszp13156491, I've added a bit to your script. I put it in a function (main) and called it using app.doScript because that neatly ties all the actions together and can be undone in a single undo. Setting the color is slightly complicated by this issue (see Uwe's info), but the problem with your script was that you were adjusting the color value of the current swatch, which was applied to all the ovals (it was applied by default when they were created I guess). So you have to make a new color.
- Mark
function main() {
var doc = app.activeDocument;
var my_ovals = doc.pages[0].ovals;
var counter = 0.5;
var counterA = 1;
var counterB = 100;
var counterC = 30;
// color values in CMYK
for (var i = my_ovals.length - 1; i >= 0; i--) {
my_ovals[i].strokeWeight = counter;
my_ovals[i].strokeColor = getCmykColor(doc, counterA, counterB, counterC, 0);
counter = counter + 0.05;
counterA = counterA + 0.5;
counterB = counterB - 0.25;
counterC = counterC + 0.38;
if (i == 0)
Explr.init(my_ovals[i].strokeColor);
}
};
function getCmykColor(doc, C, M, Y, K) {
var c;
// this will make an unnamed color
// ie. it won't show up in document
// see https://community.adobe.com/t5/indesign-discussions/coloring-a-font-with-a-rgb-etc-without-adding-the-color-to-the-document-swatches/m-p/3655060
if (doc.colors[-1].isValid) {
c = doc.colors[-1].duplicate();
c.properties = {
space: ColorSpace.CMYK,
colorValue: [C, M, Y, K],
};
}
// this will make a named swatch
else {
c = doc.colors.add({
colorValue: [C, M, Y, K],
space: ColorSpace.CMYK,
model: ColorModel.PROCESS,
name: 'C=' + C + 'M=' + M + 'Y=' + Y + 'K=' + K,
visible: false,
});
}
return c;
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Adjust colors');
Edit 2023-02-26: fixed a script error.