tjwd
New Here
tjwd
New Here
Activity
‎Dec 26, 2023
02:47 AM
I hope you don't mind me piggybacking on this post because my question is very similar. I'm making a card game for my students, and the card text is linked to a CSV using variables. In my Illustrator file, I have a rectangle with a stroke (and no fill) as the card border (let's call this "border"), and another rectangle with a fill (and no stroke) as the card title background (let's call this "background"). I want these colours to be determined by the variable called "CONTINENT", which also determines the card title text (i.e. "Europe", "Asia", "Africa", "Americas", "Oceania"), and to be interpreted as specific CMYK values. I've tried my hand at modifying your script, but I'm a complete novice when it comes to Illustrator scripting (and to JS in general), so I don't really know what I'm doing. (TBH, I don't even know how to run the script in Illustrator.) I'd be very grateful if you could lend your support. // Store all our colors in a global object with key values matching CONTINENT names:
var continents = {
Europe: createCMYK(100, 40, 0, 0),
Americas: createCMYK(0, 95, 90, 0),
Africa: createCMYK(0, 0, 0, 100),
Asia: createCMYK(0, 35, 100, 0),
Oceania: createCMYK(100, 0, 100, 0)
}
// Create a simple utility function to allow us to more easily make CMYK colors:
function createCMYK(cyan, magenta, yellow, black) {
var temp = new CMYKColor();
temp.cyan = cyan;
temp.magenta = magenta;
temp.yellow = yellow;
temp.black = black;
return temp;
}
// Now we dynamically retreive all our key CONTINENT names:
var keys = [];
for (var key in continents) keys.push(key);
// And create a RegEx to check them:
var continentRX = new RegExp("^(" + keys.join("|") + ")$");
// Equivalent to /^(Europe|Americas|Asia|Oceania|Africa)$/
// TJWD note: I'm really not sure how to modify this part...
function setCustomCrop() {
var aDoc = app.activeDocument;
var selMask = selection[0];
customCrop = selMask.name;
var CropGroup = aDoc.groupItems['CropGroup'];
var myItem = CropGroup.pageItems;
var myMask = myItem[customCrop];
myMask.locked = false;
// If the name matches our RegEx above:
if (maskRX.test(selMask.name))
selMask.fillColor = continents[selMask.name]
// ^ We use the name to match the color from our continents variable
}
... View more