Hey, you are right, it's easier to manage the data in excel instead of a script, I haven't thought about this.
So I could basically make two spreadsheets and scripts. One for the fill, one for the opacity.
I would wrangle my data in excel so I only have the area code and an RBG color associated with it. That would mostly be black or red, 1 or 2 in my spreadsheet. So I'd have something like this
How would a script look like that just associates a RBG color with a different value and colorizes my groups in AI accordingly?
For the second spreadsheet I will translate the value in my spreadsheet to the opacity I want for my groups.
So that would be two quite rudimentary scripts. But I still don't know how to even go on about using a script in AI and how to translate my thoughts into code.
You can still do both opacity and color in just one sheet and only have one script, but you'd want to ensure that your spreadsheet has distinct columns that contain the data that is going to be used by the script. So in your case as you want to assign a swatch, you can either have your document contain swatches named "1" and "2", and their color would be the color values you consider to be red or black, or you can have an extra column that has a formula that turns one of those numbers into a string because it would look up the text "RGB Red" (or rgb, whatever) in some other sheet or table that has a "1" matching with the string "RGB Red". A brute way would be to select the column and do a find-and-replace to change "1" to "RGB Red" so that you don't have to rename your document swatches to "1". This is useful in cases where you get a lot of data imported from somewhere and you don't want to change your document swatch names to "1" and "2" necessarily but also can handle cases where another type of recurring import has "A" instead of "1" where it means to be red. There you can edit your formula or its data source to contain multiple keys to match to certain strings, so you can have entries like
The new formula-powered column would be sort of like this:
The opacity could be handled in a similar way, and you can have your Illustrator-specific columns in some spot where you can quickly look and see. Or you are free to use any columns in any order, because in the script you can find your desired column by the name of its header. (Otherwise you'll have to hard-code an index-based lookup which makes it more tedious if the columns ever need to change order: you'll have to always go back to your script and fix it even when the change is only data.) I would recommend using a single csv instead of multiple ones because it's better to see the name of the shape, the color and opacity all in one place so when you highlight a row you can see exactly what appears rather than toggling between two separate files to do so.
Now you'll just need to learn how to use ES3-style javascript to ingest and split up a basic CSV (basic assumes there's no semicolons between your semicolons, so you never have a cell that is completely in quotes for the purpose of containing a literal semicolon - that's where you'll need CSV parsing code that does more advanced parsing than basic javascript String.split() function. This will be a great way to learn scripting, so do a search on this forum and see hundreds of examples of csv-reading code. The good news is that the process of reading text data and splitting it up so that a javascript array of rows and cells is created is not complicated and can be done in just a few lines of code (for basic csvs that is).
Let's leave the csv part and do a little exploration into the interesting part: making Illustrator do things!
In the script you can have a statement like this:
var doc = app.activeDocument;
doc.pathItems.getByName("45678900").fillColor = doc.swatches.getByName("RGB Red").color;
If you really have a path with such a name and a swatch with such a name, it should apply the color to it.
Now you'll have to learn how to use variables to stick a replaceable string in place of those hard-coded strings.
var doc = app.activeDocument;
var pathName = "45678900";
var swatchName = "RGB Red";
doc.pathItems.getByName(pathName).fillColor = doc.swatches.getByName(swatchName).color;
Then you can chart out some pseudo code, let's start without column headers and use hard-coded indexes to create a simplistic foundation:
{{NAME INDEX}} = 0 Note: javascript arrays begin at 0, so the 1st column in the csv would be at index 0.
{{COLOR INDEX}} = 1 (pretend the 2nd column has the swatch name)
{{DOC}} - get the active Illustrator document. (What happens when you use the app.activeDocument command and there's no document?)
{{CSV FILE}} - get csv file reference in the script somehow.
{{CSV TEXT}} - read the csv file contents into a variable that contains all of its text.
{{CSV ROWS}} - make the script split the text via nextline characters to get an array of row text.
>> do this for every row:
{{ROW CELLS}} - split each row string by semi-colons to get a collection of cells.
{{PATH NAME}} - get the cell at index {{NAME INDEX}} in the array {{ROW CELLS}}.
{{SWATCH NAME}} - get the cell at index {{COLOR INDEX}} in the array {{ROW CELLS}}.
Apply the color to the path with the scripting command:
{{DOC}}.pathItems.getByName({{PATH NAME}}).fillColor = {{DOC}}.swatches.getByName({{SWATCH NAME}}).color;