Script for changing the CMYK% values only for selective text
Hello,
I am really wondering if any1 can help me with a script which can select only the text on all art boards and change the CMYK percentage to the desired.
We have an option of selecting all the text on all the art boards and make the CMYK changes on all the texts. But we have text in multiple colours on all the art boards and want to select the text only with a certain CMYK percentages.
Meaning if some text has C:75% M:68% Y:67% K:90% ("original" values)-> I only want to change that to C:0% M:0% Y:0% K:100% ("desired" values)
The script only selects the text with "original" CMYK values and changes them into "desired" values
So i am looking for something like this:
Input box of the script:
1. option to choose text or not: Change Only the text or non text as well
2. Asking about the existing CMYK% values which needs changing
3. Desired CMYK change values
I dont even know how to code but I asked the chat GPT for the code. It did give me some code which only works for new text but does not alter the existing text on the artboards.
****************CODE************************
// Adobe Illustrator Script
// Function to prompt user for input
function promptForInput() {
var w = new Window("dialog", "CMYK Value Changer");
// Asking about the existing CMYK values
w.add("statictext", undefined, "Enter Existing CMYK Values:");
var cInput = w.add("edittext", undefined, "75");
var mInput = w.add("edittext", undefined, "68");
var yInput = w.add("edittext", undefined, "67");
var kInput = w.add("edittext", undefined, "90");
cInput.characters = 4;
mInput.characters = 4;
yInput.characters = 4;
kInput.characters = 4;
// Asking about the desired CMYK values
w.add("statictext", undefined, "Enter Desired CMYK Values:");
var cOutput = w.add("edittext", undefined, "0");
var mOutput = w.add("edittext", undefined, "0");
var yOutput = w.add("edittext", undefined, "0");
var kOutput = w.add("edittext", undefined, "100");
cOutput.characters = 4;
mOutput.characters = 4;
yOutput.characters = 4;
kOutput.characters = 4;
// OK and Cancel buttons
var buttons = w.add("group");
buttons.alignment = "center";
buttons.add("button", undefined, "OK", {name: "ok"});
buttons.add("button", undefined, "Cancel", {name: "cancel"});
if (w.show() == 1) {
return {
existingCMYK: [parseFloat(cInput.text), parseFloat(mInput.text), parseFloat(yInput.text), parseFloat(kInput.text)],
desiredCMYK: [parseFloat(cOutput.text), parseFloat(mOutput.text), parseFloat(yOutput.text), parseFloat(kOutput.text)]
};
} else {
return null;
}
}
// Function to change CMYK values of text
function changeTextCMYKValues() {
var input = promptForInput();
if (input === null) {
return; // User cancelled the input dialog
}
var existingCMYK = input.existingCMYK;
var desiredCMYK = input.desiredCMYK;
var doc = app.activeDocument;
var textFrames = doc.textFrames;
for (var i = 0; i < textFrames.length; i++) {
var textFrame = textFrames[i];
var textRange = textFrame.textRange;
for (var j = 0; j < textRange.length; j++) {
var charAttributes = textRange.characters[j].characterAttributes;
var fillColor = charAttributes.fillColor;
if (fillColor.typename === "CMYKColor" &&
fillColor.cyan === existingCMYK[0] &&
fillColor.magenta === existingCMYK[1] &&
fillColor.yellow === existingCMYK[2] &&
fillColor.black === existingCMYK[3]) {
charAttributes.fillColor = new CMYKColor();
charAttributes.fillColor.cyan = desiredCMYK[0];
charAttributes.fillColor.magenta = desiredCMYK[1];
charAttributes.fillColor.yellow = desiredCMYK[2];
charAttributes.fillColor.black = desiredCMYK[3];
}
}
}
}
// Run the script
changeTextCMYKValues();
***************************