2 Replies Latest reply on Nov 24, 2016 2:16 PM by David_Entwistle

    How to apply fillColor tint?

    David_Entwistle Level 1

      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 [i][0] and give it property value [i][1]

                // this works: doc.pathItems.getByName( fileArray[i][0] ).opacity = fileArray[i][1];

                // but the following line has no effect:

                doc.pathItems.getByName( fileArray[i][0] ).fillColor.tint = fileArray[i][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.

        • 1. Re: How to apply fillColor tint?
          pixxxel schubser Level 5

          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[i][0] );
                  if (pI.fillColor.tint == 100) { // change only if tint value == 100
                  pI.fillColor.tint = pI.fillColor.tint *(fileArray[i][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

           

          1 person found this helpful
          • 2. Re: How to apply fillColor tint?
            David_Entwistle Level 1

            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.