sky-chaser-high / adobe-illustrator-scripts

This is a collection of scripts for Adobe Illustrator.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

importCSVtoSwatch

creold opened this issue · comments

I suggest adding support for CSV with HEX column. Sample: https://gist.github.com/creold/a605cd81a89e9884c384df1683c20654

Hi Sergey.
Good idea.
I'll add the feature.

Regarding the setName(color) function. As far as I can tell, if the name is empty, Illustrator will automatically assign it in the format "C=.... M=... Y=... K=..." and "R=... G=... B=...". Or you added the condition if (color.mode == ... for safety?

I thought the swatch name had to be set.
Thanks for letting me know.

In any case, it never hurts to be careful. Especially in Illustrator with its unpredictable bugs. Perhaps forming a name within the function will help avoid errors.

Added Hex color.

I also looked at how Illustrator works when the hex string in the input field is shorter than 6 characters. Illustrator adds leading zeros. To avoid errors, you can add the same behavior to the function.

function getHexColor(values) {
    var val = values[0];
    val = val.replace(/[^0-9A-F]/gi, '');
    if (val.length > 0 && val.length < 6) {
      val = ('000000' + val).slice(-6);
    }
    var colors = val.match(/../g);
    return {
        name: (values[1]) ? values[1] : val.toUpperCase(),
        red: parseInt(colors[0], 16),
        green: parseInt(colors[1], 16),
        blue: parseInt(colors[2], 16)
    };
}

If the Hex color is 3-digit, it modified the behavior to be similar to CSS.
Otherwise, it now fills in with 0.