SpotColor to GrayColor converter (javaScript)
this edited change spot color grayscale, aimed @ color called "spot black". reason better using "edit/edit colors/convert grayscale" tones stay same value. i'm sure improved, i'm sharing if having issues having might have easier time fixing it. script originated carloscanto on discussion http://forums.adobe.com/thread/1267562?tstart=0 , discussed further in discussion http://forums.adobe.com/message/5610447#5610447. enjoy.
// script.name = grayscalefromspotblack.jsx; // script.description = changes art color spot swatch named "spot black", grayscale tones; // script.requirements = opened document; // script.parent = carloscanto // 08/08/13; // script.elegant = false; // reference http://forums.adobe.com/thread/1267562?tstart=0 && http://forums.adobe.com/message/5610447#5610447 // note: color values rounded nearest integer, avoid values black = 99.99999999999999 // hidden and/or locked objects ignored, objects in hidden and/or locked layers #target illustrator var idoc = app.activedocument; var pi = idoc.pathitems; var tf = idoc.textframes; var fcounter = 0; var scounter = 0; var gcounter = 0; //apply grayscale paths , gradient stops (j=0; j<pi.length; j++) { var ipath = pi[j]; if (ipath.hidden==false && ipath.locked==false) { if (meettheparents(ipath) == "islayerfree"){ if (islayerfree(ipath.parent)){ changepath(ipath); } else { if (isgroupfree(ipath)){ changepath(ipath); } } } } } // choose text , change (t=0; t<tf.length; t++) { var itxtfrm = tf[t]; if (itxtfrm.locked==false && itxtfrm.hidden==false) { if (meettheparents(itxtfrm) == "islayerfree"){ if (islayerfree(itxtfrm.parent)){ changetext(itxtfrm); } else { if (isgroupfree(itxtfrm)){ changetext(itxtfrm); } } } } } alert(fcounter + ' fill(s), ' + scounter + ' stroke(s) & ' + gcounter + ' gradient stop(s) processed.'); function meettheparents(pageitem){ if (pageitem.parent.typename = "layer"){ return "islayerfree"; } else if (pageitem.parent.typename = "groupitem"){ return "isgroupfree"; } } function isgroupfree(groupitem){ if (groupitem.parent.hidden==false && groupitem.parent.editable==true){ if (groupitem.parent.typename == "layer"){ var greatgpa = groupitem.parent; islayerfree(greatgpa); }else if (groupitem.parent.typename = "groupitem"){ var gpa = groupitem.parent; if (isgroupfree(gpa)); return true } else { return false } } } function islayerfree(layer){ if (layer.locked == false && layer.visible == true){ var gpa = layer.parent; islayerfree(gpa); return true } else { return false } } // changes text function changetext(textframe){ var chars = textframe.characters; (c=0; c<chars.length; c++) { var ltr = chars[c]; if (ltr.characterattributes.fillcolor.typename == "spotcolor"){ if (ltr.characterattributes.fillcolor.spot.name == "spot black"){ var fillk = math.round(ltr.characterattributes.fillcolor.tint); spottogrey (ltr, true, false, fillk); fcounter++; } } if (ltr.characterattributes.strokecolor.typename == "spotcolor"){ if (ltr.characterattributes.strokecolor.spot.name == "spot black") { var strokek = math.round(ltr.characterattributes.strokecolor.tint); spottogrey (ltr, false, true, strokek); scounter++; } } } }; //actually changes paths function changepath(pathitem){ var fillcolor = pathitem.fillcolor; if (fillcolor.typename == "spotcolor") { if (fillcolor.spot.name == "spot black") { var fillk = math.round(fillcolor.tint); spottogrey (pathitem, true, false, fillk); fcounter++; } } else if (fillcolor.typename == "gradientcolor") { var stops = pathitem.fillcolor.gradient.gradientstops; (s=0; s<stops.length; s++) { var istop = stops[s]; var stopcolor = istop.color; if (stopcolor.typename == "spotcolor") { if (stopcolor.spot.name == "spot black") { var stopk = math.round(stopcolor.tint); istop.color = graycolor; istop.color.gray = stopk; gcounter++; } } } } var strokecolor = pathitem.strokecolor; if (strokecolor.typename == "spotcolor") { if (strokecolor.spot.name == "spot black") { var strokek = math.round(strokecolor.tint); spottogrey (pathitem, false, true, strokek); scounter++; } } else if (strokecolor.typename == "gradientcolor") { var stops = pathitem.strokecolor.gradient.gradientstops; (s=0; s<stops.length; s++) { var istop = stops[s]; var stopcolor = istop.color; if (stopcolor.typename == "spotcolor") { if (stopcolor.spot.name == "spot black") { var stopk = math.round(stopcolor.tint); istop.color = graycolor; istop.color.gray = stopk; gcounter++; } } } } } function spottogrey (path, fill, stroke, k) { if (fill) { path.fillcolor = graycolor; path.fillcolor.gray = k; } if (stroke) { path.strokecolor = graycolor; path.strokecolor.gray = k; } } a file shows script hosted here https://docs.google.com/file/d/0bzeojsydhh_weknoytfzvhvaoxm/edit?usp=sharing until forget why it's saved there , delete it.
nice work on progress/additions have made through these threads, stuff, thanks sharing , carloscanto well.
More discussions in Illustrator Scripting
adobe
Comments
Post a Comment