Copy link to clipboard
Copied
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();
***************************
Copy link to clipboard
Copied
Ignore this... Should have read the post better before answering.
Copy link to clipboard
Copied
Can you share a sample Illustrator file for inspection?
Copy link to clipboard
Copied
I wonder if you need a script for this.
If you select a text with the color you want to change, you can select same fill color from the select menu and change the color of the selection into something else.
This will also change other objects with that color.
If you want only text objects to change, use Select > Objects > All Text Objects.
Select > Inverse.
Lock or hide the objects and select the text with the color you want to change, select same fill color, change the color and unlock/show all.
Copy link to clipboard
Copied
So far, I don't see any problems with your code. I have recolored the default color characters in the text frames of the document to the new color. What confuses me in the description is that your script doesn't work with existing texts, but with new ones. Maybe you can record a GIF, MP4 and actually demonstrate your vector file.
Copy link to clipboard
Copied
Hello @vinay351218940xn7,
We hope Ton and Sergey's suggestions have been helpful in resolving the issue. If you still need assistance, please feel free to reply to this thread. We're here to support you.
Thanks,
Anubhav