Copy link to clipboard
Copied
Hello – my script reads a CSV file (which holds path names and corresponding tint values) and tries to apply a tint to each named path. All paths have previously been filled with 100% of a Spot color.
The script (below) builds on something that Muppet Mark generously supplied for someone else's question a while back. It works fine if I change the opacity of the objects, but not if I change the tints. Can anyone please show what I'm doing wrong?
Many thanks.
#target Illustrator
applydatafile();
function applydatafile() {
if ( app.documents.length == 0 ) { return; }
var doc, csvFile, i, fileArray;
csvFile = File.openDialog("Choose the CSV file");
if ( !csvFile.exists ) { return; }
fileArray = readInCSV( csvFile );
doc = app.activeDocument;
// For each line of the data file...
for ( i = 0; i < fileArray.length; i++ ) {
// ...get the named path [0] and give it property value [1]
// this works: doc.pathItems.getByName( fileArray[0] ).opacity = fileArray[1];
// but the following line has no effect:
doc.pathItems.getByName( fileArray[0] ).fillColor.tint = fileArray[1];
};
};
function readInCSV( fileObj ) {
var fileArray, thisLine, csvArray;
fileArray =[];
fileObj.open( 'r' );
while( !fileObj.eof ) {
thisLine = fileObj.readln();
csvArray = thisLine.split( ',' );
fileArray.push( csvArray );
};
fileObj.close();
return fileArray;
};
CSV file contents:
one,35
two,55
three,75
four,95
Message was edited by: David Entwistle to aid clarity.
how about this?
...applydatafile();
function applydatafile() {
if ( app.documents.length == 0 ) { return; }
var doc, csvFile, i, fileArray, pI;
csvFile = File.openDialog("Choose the CSV file");
if ( !csvFile.exists ) { return; }
fileArray = readInCSV( csvFile );
doc = app.activeDocument;
// For each line of the data file...
for ( i = 0; i < fileArray.length; i++ ) {
pI = doc.pathItems.getByName( fileArray[0] );
if (pI.fillColor.tint == 100) { /
Copy link to clipboard
Copied
how about this?
applydatafile();
function applydatafile() {
if ( app.documents.length == 0 ) { return; }
var doc, csvFile, i, fileArray, pI;
csvFile = File.openDialog("Choose the CSV file");
if ( !csvFile.exists ) { return; }
fileArray = readInCSV( csvFile );
doc = app.activeDocument;
// For each line of the data file...
for ( i = 0; i < fileArray.length; i++ ) {
pI = doc.pathItems.getByName( fileArray[0] );
if (pI.fillColor.tint == 100) { // change only if tint value == 100
pI.fillColor.tint = pI.fillColor.tint *(fileArray[1]/100);
}
}
}
function readInCSV( fileObj ) {
var fileArray, thisLine, csvArray;
fileArray =[];
fileObj.open( 'r' );
while( !fileObj.eof ) {
thisLine = fileObj.readln();
csvArray = thisLine.split( ',' );
fileArray.push( csvArray );
}
$.writeln (fileArray);
fileObj.close();
return fileArray;
}
Have fun
Copy link to clipboard
Copied
Thank you! That does the trick, and very neatly.
(I had to add some semi-colons after the closing braces, lines 15–17, but not sure if that's something to do with my set-up.)
Very grateful for your coding and your time – thank you again.