Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

need a tweek to script

Explorer ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

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
TOPICS
Scripting

Views

278
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Oct 10, 2023 Oct 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;

Votes

Translate
Adobe
Guide ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

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;

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

that worked perfect!!!!!

scott

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

LATEST

Just for learning, here's a variation, that changes the suffix no matter which suffix is already applied, or adds it if none:

sw.name = spotName.replace(/(_SPOT|_CMYK)?$/, suffix);

In the regular expression, the | (bar) symbol means choose either _SPOT or _CMYK, and the ? means match the text in parentheses if it's there and the $ means match end of text—so if no suffix exists the $ replaces the end of text with the suffix.

- Mark

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines