How to read values of an imported CSV in Illustrator
Hi,
I'm new to scripting in Illustrator and I can't seem to figure out this simple thing:
I have a .csv file that contains several variables. One the variables would be mapColor. In the csv I put 'mapColor' in row 1 and the corresponding value (a string containing a hex value) in the rows underneath.
Programmatically I would like to access the mapColor values, so that I can assign a hex value to the background of a path item. But I can't seem to get the values of a specific variable.
const country = app.activeDocument.pathItems.getByName('country-fill-is');
const rgbValues = hexToRgb(`#${app.activeDocument.variables.getByName('mapColor')}`);
const colorRGB = new RGBColor();
color.red = rgbValues.r;
color.green = rgbValues.g;
color.blue = rgbValues.b;
country.fillColor = color;
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
I would think I'd get the variable object value with variables.getByName(), but it only returns the variable name. Any ideas on how to get an object value by variable name?
