Hallo Scripter,
Ich möchte eine Farbtabelle (ase) aus einer csv-Datei erzeugen.
Die CSV sieht in etwa so aus:
cmyk:
Red,0,100,100,10
Orange,0,65,100,0
Yellow,0,10,100,0
Green,70,40,100,0
Blue,100,50,0,20
Violet,50,100,20,0
rgb:
meinRed,255,0,0
meinOrange,255,100,0
meinYellow,0,255,0
meinGreen,255,255,0
meinBlue,255,0,0
meinViolet,255,0,255
Dazu hab ich mir einmal den hilfreichen Link von Monika unter
http://forums.adobe.com/message/2826210#2826210 angesehen.
Das Script dort ist toll und funktioniert in InDesign mit cmyk tadellos.
Ich bentötige dieses allerdings
a) im RGB und
b) mit dem Farb-Namen aus der Tabelle.
Also statt "r=255, g=0, b=0" eben "meinRot".
Kann mir da jemand weiterhelfen.
Mein Selbstversuch scheiterte. An folgender Stelle des Scriptes:
Code var col = colors.add({model:ColorModel.process, space:ColorSpace.RGB, colorValue:colArray, name:b}); bleibt ScriptToolkit stehen.
So sieht mein Script momentan aus. Wobei da auch noch die Funktion der Übergabe des Farbnamens fehlt.
Code //#target indesign function main() { if (isOSX()) { var csvFile = File.openDialog('Select a CSV File', function (f) { return (f instanceof Folder) || f.name.match(/\.csv$/i);} ); } else { var csvFile = File.openDialog('Select a CSV File','comma-separated-values(*.csv):*.csv;'); } if (csvFile != null) { fileArray = readInCSV(csvFile); var columns = fileArray[0].length; //alert('CSV file has ' + columns + ' columns…'); var rows = fileArray.length; //alert('CSV file has ' + rows + ' rows…'); if (columns == 4 && rows > 0) { exchangeSwatches(csvFile); } else { var mess = 'Incorrect CSV File?'; isOSX ? saySomething(mess) : alert(mess); } } else { var mess = 'Ooops!!!'; isOSX ? saySomething(mess) : alert(mess); } } main(); function exchangeSwatches(csvFile) { var docRef = app.documents.add(); with (docRef) { for (var i = unusedSwatches.length-1; i >= 0; i--) { unusedSwatches[i].remove(); } for (var a = 0; a < fileArray.length; a++) { var b = fileArray[a][0]; // First Column is name if (b == 'Red' || b == 'Green' || b == 'Blue') { b = b + '-???'; // Reserved swatch name; } /*c = parseFloat(fileArray[a][1]); // Second Column is Cyan m = parseFloat(fileArray[a][2]); // Third Column is Magenta y = parseFloat(fileArray[a][3]); // Forth Column is Yellow k = parseFloat(fileArray[a][4]); // Fifth Column is Black if (c >= 0 && c <= 100 && m >= 0 && m <= 100 && y >= 0 && y <= 100 && k >= 0 && k <= 100) { var colArray = new Array(c, m, y, k); var col = colors.add({model:ColorModel.process, space:ColorSpace.cmyk, colorValue:colArray, name:b});*/ r = parseFloat(fileArray[a][1]); // Second Column is Cyan g = parseFloat(fileArray[a][2]); // Third Column is Magenta b = parseFloat(fileArray[a][3]); // Forth Column is Yellow if (r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255 ) { var colArray = new Array(r, g, b); var col = colors.add({model:ColorModel.process, space:ColorSpace.RGB, colorValue:colArray, name:b}); } else { var mess = 'Color values are out of range?'; isOSX ? saySomething(mess) : alert(mess); } } var exchangeSwatches = swatches; var savePath = csvFile.fsName.substring(0, csvFile.fsName.length - 3); var aseFile = new File(savePath + '.ase'); saveSwatches(aseFile, exchangeSwatches); close(SaveOptions.no); } } function readInCSV(fileObj) { var fileArray = new Array(); fileObj.open('r'); fileObj.seek(0, 0); while(!fileObj.eof) { var thisLine = fileObj.readln(); var csvArray = thisLine.split(','); fileArray.push(csvArray); } fileObj.close(); return fileArray; } function saySomething(stringObj) { var speakThis = 'say "' + stringObj + '" using "Fred"'; app.doScript(speakThis, 1095978087); // AppleScript } function isOSX() { return $.os.match(/Macintosh/i); } Da das Script sicher eine echte Bereicherung für viele User ist, wäre eventuell sogar eine Umsetzung für Photoshop mit HEX-Werten eine feine Sache.
Könnt ihr mir bitte helfen?
Beste Grüße
Karsten