Skip to main content
NOOOOOOOOOO!!!!!!
Participant
January 23, 2015
Answered

Changing color from Swatch to Spot color

  • January 23, 2015
  • 2 replies
  • 1598 views

Hello,

I have almsot figured this out but have on hangup.  I am trying to replace a color with another color from a Pantone library. I am using Illustrator CS6.

I have this script which I found on here:

#target illustrator

var docRef = app.activeDocument;

with (docRef) {

var replaceColor = swatches.getByName('Pantone 152 C').color;

for (var i = 0; i < pathItems.length; i++) {

with (pathItems) {

if (filled == true && fillColor instanceof SpotColor) {

if (fillColor.spot.name == '  HCS Orange') fillColor = replaceColor;

}

}

}

for (var j = 0; j < stories.length; j++) {

with (stories) {

for (var k = 0; k < characters.length; k++) {

with (characters.characterAttributes) {

if (fillColor instanceof SpotColor) {

if (fillColor.spot.name == '  HCS Orange') fillColor = replaceColor;

}

if (strokeColor instanceof SpotColor) {

if (strokeColor.spot.name == '  HCS Orange') strokeColor = replaceColor;

}

}

}

}

}

}

Which works,  but only if the new PMS color is added to the swatch list.  It seems I cannot get the swatch in the list easily using a script(which I have no experience with) or using an action.  Nor can I change the name after var replacecolor as it seems to only look for the swatch panel and not the color group or color book panel

Any suggestions would be helpful, I am looking at having to change 30,000 files.

Thanks,

Matt

This topic has been closed for replies.
Correct answer Disposition_Dev

are the target color and destination color the same in each file? in other words, are you always changing "HCS Orange" to "Pantone 152C"?

if so, you could just define the pantone color at the beginning of your code. like so:

#target illustrator

var docRef = app.activeDocument;

var swatches = docRef.swatches;

try {

     var replaceColor = swatches.getByName('Pantone 152C').color;

}

catch (err){

     var replaceColor = docRef.spots.add();

     replaceColorColor = new CMYKColor();

     replaceColorColor.cyan = 4.84;

     replaceColorColor.magenta = 66.58;

     replaceColorColor.yellow = 100;

     replaceColorColor.black = 0.21;

     replaceColor.name = 'Pantone 152C';

     replaceColor.color = replaceColorColor;

     replaceColor.colorType = ColorModel.SPOT;

     replaceColor.tint = 100;

}

2 replies

Disposition_Dev
Legend
January 27, 2015

Any luck?

NOOOOOOOOOO!!!!!!
Participant
January 27, 2015

William,

While running the script you wrote and then the one I had already, it seemed to do exactly what I needed.  I will be testing batching them shortly.

Disposition_Dev
Legend
January 27, 2015

You could easily merge them. Just place the above code in front of the code you're using to replace the colors and then you'll only have to run one script on each file and you shouldn't get any error messages.

Glad it worked for ya. = )

Disposition_Dev
Disposition_DevCorrect answer
Legend
January 26, 2015

are the target color and destination color the same in each file? in other words, are you always changing "HCS Orange" to "Pantone 152C"?

if so, you could just define the pantone color at the beginning of your code. like so:

#target illustrator

var docRef = app.activeDocument;

var swatches = docRef.swatches;

try {

     var replaceColor = swatches.getByName('Pantone 152C').color;

}

catch (err){

     var replaceColor = docRef.spots.add();

     replaceColorColor = new CMYKColor();

     replaceColorColor.cyan = 4.84;

     replaceColorColor.magenta = 66.58;

     replaceColorColor.yellow = 100;

     replaceColorColor.black = 0.21;

     replaceColor.name = 'Pantone 152C';

     replaceColor.color = replaceColorColor;

     replaceColor.colorType = ColorModel.SPOT;

     replaceColor.tint = 100;

}