Yes, you´re right. If you use headers starting with "i=1" is the correct way. In my example CSV I´m working without header. Therefore - no mistake in the code, just a question of using a header or not. Here once again my version of the code (using header). There´s one small change in the code, that fixes a mistake in the "coloring loop", that caused an error message: #target illustrator function test(){ function readSemicolonCSV(filePath){ var f = File(filePath); if(!f.exists){ alert(f + " is not found."); return false; } var str = ""; f.open("r"); str = f.read(); f.close(); return str; } function getCells(str){ var rows = str.split(/[\n\r]/g); for(var i=0; i<rows.length; i++){ rows = rows.split(/;/g); }; return rows; } function applyColorSettingsRow(regionName, colorName){ var doc = app.activeDocument, thisRegionShape, thisColor; var anzPfade = doc.layers.getByName(regionName).pathItems.length; try{ for (var i=0; i<anzPfade;i++){ thisRegionShape = doc.layers.getByName(regionName).pathItems; thisColor = doc.swatches.getByName(colorName); thisRegionShape.fillColor = thisColor.color; } } catch(e) { $.writeln("Region: " + regionName + "\tColor: " + colorName + "\r" + e + "\n\n"); } } if(app.documents.length == 0){ alert("No open documents detected."); return; } var csvFile = File.openDialog("Open CSV File", "*.csv"); if(!csvFile){ alert("No file chosen"); return; } var data = getCells(readSemicolonCSV(csvFile)); var doc = app.activeDocument; for(var i=1; i<data.length; i++){ applyColorSettingsRow(data[0], data[1]); }; }; test();
... View more