• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to apply fillColor tint?

Explorer ,
Nov 24, 2016 Nov 24, 2016

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.

TOPICS
Scripting

Views

706

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 24, 2016 Nov 24, 2016

Hi David_Entwistle

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) { /

...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 24, 2016 Nov 24, 2016

Copy link to clipboard

Copied

Hi David_Entwistle

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 24, 2016 Nov 24, 2016

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines