Answered
switch statement to change swatches
- October 30, 2024
- 2 replies
- 280 views
Hello,
I wanted to write this simple (in my mind) script that would change certain (listed) spot colors to process CMYK swatches + removes them from the list (by replacing them with unnamed swatch using method i found somwhere on adobe forums).
app.activeDocument.colors.everyItem().properties = {space:ColorSpace.CMYK};
app.activeDocument.colors.everyItem().properties = {space:ColorSpace.CMYK, model:ColorModel.PROCESS};
var swatches = app.activeDocument.swatches;
var C = [100,0,0,0];
var M = [0,100,0,0];
var K = [0,0,0,100];
function replaceSwatch(ogName) {
const doc = app.documents[0];
const swatch = doc.colors.itemByName(ogName);
const newSwatch = doc.colors[-1].duplicate();
newSwatch.properties = swatch.properties;
swatch.remove(newSwatch);
}
for (var i = 0; i < swatches.length; i++) {
var swatch = swatches[i];
var swatchName = swatch.name;
switch (swatchName) {
case "Outside_Bleed":
swatch.colorValue = M;
replaceSwatch(swatchName);
break;
case "Artios_Dimensions and text":
swatch.colorValue = C;
replaceSwatch(swatchName);
break;
case "Dimensions_&_Text":
swatch.colorValue = C;
replaceSwatch(swatchName);
break;
case "Cut":
swatch.colorValue = K;
replaceSwatch(swatchName);
break;
case "Artios_Cut":
swatch.colorValue = K;
replaceSwatch(swatchName);
break;
case "Artios_Outside coating":
swatch.colorValue = C;
replaceSwatch(swatchName);
break;
case "Artios_Inside coating":
swatch.colorValue = C;
replaceSwatch(swatchName);
break;
case "Crease":
swatch.colorValue = K;
replaceSwatch(swatchName);
break;
case "Artios_Crease":
swatch.colorValue = K;
replaceSwatch(swatchName);
break;
case "Print_Image":
swatch.colorValue = C;
replaceSwatch(swatchName);
break;
case "Artios_Print images":
swatch.colorValue = C;
replaceSwatch(swatchName);
break;
case "Artios_Partial cut":
swatch.colorValue = K;
replaceSwatch(swatchName);
break;
default:
}
}
But it only goes through some of the cases and finishes. I have to run it couple times to get rid of all unwanted swatches.
Is is because i've used switch statement?
I'm attaching test indd file i made as well. (it may look weird to change spot to process colors, but that's the beauty of my workplace 🙂 )
