/*
Run this script to rename swatch rgb color to corresponding hex value
For example, 'R=108 G=125 B=87' will be '#6c7d57'
Note: script works with RGB color only.
Befor run script select swatch colors in illustrator's Swathes Panel.
*/
var myDoc = app.activeDocument;
var selSwatches = myDoc.swatches.getSelected();
for (var i=0; i<selSwatches.length; i++)
{
swcolor = selSwatches[i].color;
if (swcolor.typename=='RGBColor')
{
selSwatches[i].name = rgbToHex(swcolor.red, swcolor.green, swcolor.blue) ;
}
}
function rgbToHex(r, g, b)
{
var hex = '#';
for (var i = 0; i < 3; ++i)
{
var n = typeof arguments[i] == 'number' ? arguments[i] : parseInt(arguments[i]);
if (isNaN(n) || n < 0 || n > 255)
{
return null;
}
hex += (n < 16 ? '0' : '') + n.toString(16);
}
return hex;
}
謝謝你,這是完美的! 我試圖upvote你的帖子,但它不會讓我。 –