Hi,
Thanks for the input. Yes I am looking at using them through the GUI. I'm not very familiar with scripting so you will have to excuse my ignorance. Is the script that you mention to convert the CSV file to an array a script that I would be able to download online? I tried to do a search and got several results for different programming language. As well once I have the array file how do I import that into indesign so that it will recognize it as a swatch?
The following is an example of the data that I am putting in.
Name Cyan Magenta Yellow Black
1001 95 0 69 78
1007 53 0 60 0
1012 35 0 83 0
1017 100 0 85 14
Thanks for you help!
AM
From Excel you save your file out as text using something to delimit the values 'comma' CSV and 'tab' TDT are the common ones to use. A script can then read this information in. I started this script using CS2 and Indesign I don't think you could save '.ase' from any other Adobe app. Things may have changed but Im buried taking a look at the CS5 trial to put any time into this just now. Only 24 days left…
I did open and run and it still worked so you may get some mileage. I did start to add RGB and LAB as switches but that may have to come L8R… When I can start to use dialogs…
CSV should be like:
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
The sample script…
#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 == 5 && 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.remove();
}
for (var a = 0; a < fileArray.length; a++) {
var b = fileArray[0]; // First Column is name
if (b == 'Cyan' || b == 'Magenta' || b == 'Yellow' || b == 'Black') {
b = b + '-???'; // Reserved swatch name;
}
c = parseFloat(fileArray[1]); // Second Column is Cyan
m = parseFloat(fileArray[2]); // Third Column is Magenta
y = parseFloat(fileArray[3]); // Forth Column is Yellow
k = parseFloat(fileArray[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});
} 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 - 4);
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);
}
Hope it works 4U… Cyan, Magenta, Yellow & Black are reserved colour names so I just added '-???' as a temporary fix…