Skip to main content
Known Participant
October 10, 2023
Answered

need a tweek to script

  • October 10, 2023
  • 1 reply
  • 414 views

need to change a bit on this script, specifically how it renames the color...

currently it is just adding the suffix "_CMYK" to the color swatch but because the name currently is "COLOR_SPOT" it ends up becoming "COLOR_SPOT_CMYK".

How can i change it to remove "_SPOT" and then append the suffix "_CMYK"  so the new name will be  "COLOR_CMYK"

 

the existing color will always have "_SPOT" at the end of the swatch name
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
//current script....

//@target illustrator
main();

function main() {
var suffix = '_CMYK';
var isRmvSpot = true; // true of false

var doc = app.activeDocument;
var len = doc.spots.length;
var isRgb = /rgb/i.test(doc.documentColorSpace);

for (var i = 0; i <= len - 1; i++) {
if (doc.spots[i].colorType === ColorModel.REGISTRATION) continue;
var spotName = doc.spots[i].name;
var spotValue = doc.spots[i].getInternalColor();
var sw = doc.swatches.add();
sw.name = spotName + suffix;
var newColor = setColor(spotValue, isRgb);
sw.color = newColor;
}

if (isRmvSpot && len > 0) doc.spots.removeAll();
}

function setColor(arr, isRgb) {
var color = isRgb ? new RGBColor() : new CMYKColor();
if (isRgb) {
color.red = arr[0];
color.green = arr[1];
color.blue = arr[2];
} else {
color.cyan = arr[0];
color.magenta = arr[1];
color.yellow = arr[2];
color.black = arr[3];
}
return color;
}
 
 
//scott
This topic has been closed for replies.
Correct answer femkeblanco

Change this line

sw.name = spotName + suffix;

to

// if spotName has the suffix _SPOT, remove it
if (spotName.slice(-5) == "_SPOT") sw.name = spotName.slice(0, -5) + suffix
else sw.name = spotName + suffix;

1 reply

femkeblanco
femkeblancoCorrect answer
Legend
October 10, 2023

Change this line

sw.name = spotName + suffix;

to

// if spotName has the suffix _SPOT, remove it
if (spotName.slice(-5) == "_SPOT") sw.name = spotName.slice(0, -5) + suffix
else sw.name = spotName + suffix;
@Js1212Author
Known Participant
October 10, 2023

that worked perfect!!!!!

scott