Carlos wrote a script in response to the above thread. It changes CMYK black, and grayscale black to a swatch called "spot black". It's awesome, but it's only aimed at paths. I've made some adjustments to prevent it from effecting white and unpainted objects. I'm going to need it to work on text and gradients. Right now I am working on text.
I've tried to use the same logic that works on the paths on text, but I'm missing something. Help help.
This is the latest working version, it does not effect text or gradients.
// script.name = cmykBlackNgrayscaleToSpotBlack.jsx; // script.description = changes art color from standard CMYK Black and Grayscale tones to an EXISTING Spot swatch named "spot black"; // script.requirements = an opened document; // script.parent = CarlosCanto // 08/08/13; // script.elegant = false; // reference http://forums.adobe.com/thread/1267562?tstart=0 // Note: color values get rounded to the nearest integer, to avoid values like black = 99.99999999999999 // Hidden and/or Locked Objects will be ignored, as well as objects in Hidden and/or Locked Layers #target Illustrator var idoc = app.activeDocument; var pi = idoc.pathItems; var sw = idoc.swatches["spot black"]; var fcounter = 0; var scounter = 0; for (j=0; j<pi.length; j++) { var ipath = pi[j]; if (ipath.layer.visible==true && ipath.layer.locked==false && ipath.hidden==false && ipath.locked==false) { var fillColor = ipath.fillColor; if (fillColor.typename == "CMYKColor") { if (isColorBlack (fillColor)) { var fillk = Math.round(fillColor.black); cmykBlackToSpot (ipath, true, false, fillk); fcounter++; } } else if (fillColor.typename == "GrayColor") { if (grayNotWhiteOrClear (fillColor)) { var fillk = Math.round(fillColor.gray); cmykBlackToSpot (ipath, true, false, fillk); fcounter++; } } var strokeColor = ipath.strokeColor; if (strokeColor.typename == "CMYKColor") { if (isColorBlack (strokeColor)) { var strokek = Math.round(strokeColor.black); cmykBlackToSpot (ipath, false, true, strokek); scounter++; } } else if (strokeColor.typename == "GrayColor") { if (grayNotWhiteOrClear (strokeColor)) { var strokek = Math.round(strokeColor.gray); cmykBlackToSpot (ipath, false, true, strokek); scounter++; } } } } alert(fcounter + ' Fill(s) & ' + scounter + ' stroke(s) processed'); function cmykBlackToSpot (path, fill, stroke, k) { if (fill) { path.fillColor = sw.color; path.fillColor.tint = k; } if (stroke) { path.strokeColor = sw.color; path.strokeColor.tint = k; } } function isColorBlack (cmykColor) { var c = Math.round(cmykColor.cyan); var m = Math.round(cmykColor.magenta); var y = Math.round(cmykColor.yellow); var k = Math.round(cmykColor.black); if (c==0 && m==0 && y==0 && k != 0) return true else return false } function grayNotWhiteOrClear (GrayColor) { var pct = Math.round(GrayColor.gray); if (pct != 0) return true else return false }
This is the version I'm working on now where I'm trying to include the text.
// script.name = cmykBlackNgrayscaleToSpotBlack.jsx; // script.description = changes art color from standard CMYK Black and Grayscale tones to an EXISTING Spot swatch named "spot black"; // script.requirements = an opened document; // script.parent = CarlosCanto // 08/08/13; // script.elegant = false; // reference http://forums.adobe.com/thread/1267562?tstart=0 // Note: color values get rounded to the nearest integer, to avoid values like black = 99.99999999999999 // Hidden and/or Locked Objects will be ignored, as well as objects in Hidden and/or Locked Layers #target Illustrator var idoc = app.activeDocument; var pi = idoc.pathItems; var sw = idoc.swatches["spot black"]; var ch = idoc.textFrames[0].characters[0]; var fcounter = 0; var scounter = 0; for (j=0; j<pi.length; j++) { var ipath = pi[j]; if (ipath.layer.visible==true && ipath.layer.locked==false && ipath.hidden==false && ipath.locked==false) { var fillColor = ipath.fillColor; if (fillColor.typename == "CMYKColor") { if (isColorBlack (fillColor)) { var fillk = Math.round(fillColor.black); cmykBlackToSpot (ipath, true, false, fillk); fcounter++; } } else if (fillColor.typename == "GrayColor") { if (grayNotWhiteOrClear (fillColor)) { var fillk = Math.round(fillColor.gray); cmykBlackToSpot (ipath, true, false, fillk); fcounter++; } } var strokeColor = ipath.strokeColor; if (strokeColor.typename == "CMYKColor") { if (isColorBlack (strokeColor)) { var strokek = Math.round(strokeColor.black); cmykBlackToSpot (ipath, false, true, strokek); scounter++; } } else if (strokeColor.typename == "GrayColor") { if (grayNotWhiteOrClear (strokeColor)) { var strokek = Math.round(strokeColor.gray); cmykBlackToSpot (ipath, false, true, strokek); scounter++; } } } } for (t=0; t<ch.length; t++) { var txt = ch[t]; if (txt.layer.visible==true && txt.layer.locked==false && txt.hidden==false && txt.locked==false) { var fillColor = txt.fillColor; if (fillColor.typename == "CMYKColor") { if (isColorBlack (fillColor)) { var fillk = Math.round(fillColor.black); cmykBlackToSpot (txt, true, false, fillk); fcounter++; } } else if (fillColor.typename == "GrayColor") { if (grayNotWhiteOrClear (fillColor)) { var fillk = Math.round(fillColor.gray); cmykBlackToSpot (txt, true, false, fillk); fcounter++; } } var strokeColor = txt.strokeColor; if (strokeColor.typename == "CMYKColor") { if (isColorBlack (strokeColor)) { var strokek = Math.round(strokeColor.black); cmykBlackToSpot (txt, false, true, strokek); scounter++; } } else if (strokeColor.typename == "GrayColor") { if (grayNotWhiteOrClear (strokeColor)) { var strokek = Math.round(strokeColor.gray); cmykBlackToSpot (txt, false, true, strokek); scounter++; } } } } alert(fcounter + ' Fill(s) & ' + scounter + ' stroke(s) processed'); function cmykBlackToSpot (path, fill, stroke, k) { if (fill) { path.fillColor = sw.color; path.fillColor.tint = k; } if (stroke) { path.strokeColor = sw.color; path.strokeColor.tint = k; } } function isColorBlack (cmykColor) { var c = Math.round(cmykColor.cyan); var m = Math.round(cmykColor.magenta); var y = Math.round(cmykColor.yellow); var k = Math.round(cmykColor.black); if (c==0 && m==0 && y==0 && k != 0) return true else return false } function grayNotWhiteOrClear (GrayColor) { var pct = Math.round(GrayColor.gray); if (pct != 0) return true else return false }
Here is a test file
https://docs.google.com/file/d/0BzEoJSYDhH_WdENjc092SF9GN0U/edit?usp=sharing
Thanks for playing.