15 Replies Latest reply: Nov 26, 2014 11:46 PM by imagecollection RSS

    Export of color values to Excel

    EWO54 Community Member

      Is there a method to export the RGB and/or CYMK color values of all of the colors in a specific color group or swatch into Excel (i.e. R114, G21, B37)??

        • 1. Re: Export of color values to Excel
          imagecollection Community Member

          here is the basics.

           

          Don't forget to update the path in the first line!

           

          var listfile = "C:/Users/me/list.csv";  //add Filename
          var doc = activeDocument;
          var col = doc.swatches;
          var info = new Array();
          if(doc.documentColorSpace == DocumentColorSpace.CMYK)
          {
             info.push("I.D.,C,M,Y,K");
             for(var i = 0; i < col.length;i++)
             {
                  if(col[i].color=="[CMYKColor]")
                  {
                      var c = Math.round(col[i].color.cyan);
                      var m = Math.round(col[i].color.magenta);
                      var y = Math.round(col[i].color.yellow);
                      var k = Math.round(col[i].color.black);
                     info.push(i+","+c+","+m+","+y+","+k);
                  } else {info.push(i);}
              }
          }
          if(doc.documentColorSpace == DocumentColorSpace.RGB)
          {
             info.push("I.D.,R,G,B");
             for(var i = 0; i < col.length;i++)
             {
                  if(col[i].color=="[RGBColor]")
                  {
                      var r = Math.round(col[i].color.red);
                      var g = Math.round(col[i].color.green);
                      var b = Math.round(col[i].color.blue);
                      info.push(i+","+r+","+g+","+b);
                  }  else {info.push(i);}
              }
          }
          var thefile = new File(listfile); //pass the file to a Variable
          var isopen = thefile.open("w"); //open file for editing
          if (isopen)//test file is open
          {
             thefile.seek(0,0);
             for(var j = 0; j < info.length; j++)
             {
             thefile.writeln(info[j]);
             }
             thefile.close();
          }
          
          
          • 2. Re: Export of color values to Excel
            EWO54 Community Member

            Please forgive my ignorance, but am I supposed add this as a new script file in Adobe Illustrator?  How does this get executed on my iMac?  thanks

            • 3. Re: Export of color values to Excel
              imagecollection Community Member

              Sorry I post in the scripting forum all the time so forget when I put scripts elsewhere...

               

              I'm not sure what version of the software you are using or if you have Extendscript Toolkit installed.

              I also don't know your level of comfit with anything I'm about to go through.

              But I'll assume some things and you can ask for more if needed...

               

              I never use mac so have no idea if this is all correct... someone correct me if i'm wrong please

               

              save the code above in to a file with extension .jsx

              and save into (for mac) "Applications / Adobe\Adobe Illustrator "your program version"\Presets\en_GB\Scripts"

              after restarting illustrator you will find the script in File->Scripts

              don't forget to change the path in the first line of the file...

              (for mac it would be something like) ~/directoryForList/list.csv

               

              I have not put basic safegaurds in this script to check a document is open etc... so it may sometimes error...

              • 4. Re: Export of color values to Excel
                EWO54 Community Member

                Thanks for all of the help - unfortunately you are working with a amateur.  I was able to save the file as .jsx into the Illustrator Scripts folder and it can be accessed as you indicated.  However when selected - nothing happens - no error message of any kind.

                • 5. Re: Export of color values to Excel
                  imagecollection Community Member

                  you did change the Path?

                  ~/directoryForList/list.csv

                  this refers to a folder named directoryForList within your home directory containing a file named list.csv.

                   

                  the script will not create this folder. it needs to exist before running the script. create it manually.

                  (Sorry I should have said that)

                   

                  with a document open. run the script.

                  then go to the folder above and see if it has a .csv file in it. that should have all the values in it...

                   

                  Fingers crossed...

                  • 6. Re: Export of color values to Excel
                    EWO54 Community Member

                    I used the following path "Macintosh HD/Users/tonied59/Desktop/EOlist/list.csv" and have a list.csv file saved there.  Still no joy.

                    • 7. Re: Export of color values to Excel
                      EWO54 Community Member

                      I duplicated the folder name you provided previously "Macintosh HD/Users/tonied59/Desktop/directoryForList/list.csv".  Still no luck.

                      • 8. Re: Export of color values to Excel
                        imagecollection Community Member

                        sorry about my lack of knowledge with macs, I'll see if I can get some insite from some mac users in the scripting forum and get back to you.

                        • 9. Re: Export of color values to Excel
                          Silly-V Community Member

                          try "~Desktop/EOlist/list.csv"

                           

                          If this doesn't work and the file has been destroyed (Oh no, make backup of the file first!), do the following before writing the file:

                          var thefile = new File(File(listfile).fsName.toString().replace("file://",''));

                          • 10. Re: Re: Export of color values to Excel
                            imagecollection Community Member

                            give this a go, I borrowed some lines from an existing default script within illustrator.

                            this time it will ask you where you want the file. and will use the document name as a file name.

                            also has a few basic checks, safegaurds.

                             

                            try {
                              if (app.documents.length > 0 ) {
                              var destFolder = null;
                              destFolder = Folder.selectDialog( 'Select folder for CSV output.', '~' );
                              if (destFolder != null) {
                              var doc = activeDocument;  
                              var col = doc.swatches;  
                              var info = new Array();
                              if(doc.documentColorSpace == DocumentColorSpace.CMYK)  
                              {  
                                info.push("I.D.,C,M,Y,K");  
                                for(var i = 0; i < col.length;i++)  
                                {  
                              if(col[i].color=="[CMYKColor]")  
                              {  
                              var c = Math.round(col[i].color.cyan);  
                              var m = Math.round(col[i].color.magenta);  
                              var y = Math.round(col[i].color.yellow);  
                              var k = Math.round(col[i].color.black);  
                                info.push(i+","+c+","+m+","+y+","+k);  
                              } else {info.push(i);}  
                              }  
                              }  
                              if(doc.documentColorSpace == DocumentColorSpace.RGB)  
                              {  
                                info.push("I.D.,R,G,B");  
                                for(var i = 0; i < col.length;i++)  
                                {  
                              if(col[i].color=="[RGBColor]")  
                              {  
                              var r = Math.round(col[i].color.red);  
                              var g = Math.round(col[i].color.green);  
                              var b = Math.round(col[i].color.blue);  
                              info.push(i+","+r+","+g+","+b);  
                              }  else {info.push(i);}  
                              }  
                              }
                              var listName = doc.name + ".csv";
                              var listfile = destFolder + "/" + listName;
                              var thefile = new File(listfile); //pass the file to a Variable  
                              var isopen = thefile.open("w"); //open file for editing  
                              if (isopen)//test file is open  
                              {  
                                thefile.seek(0,0);  
                                for(var j = 0; j < info.length; j++)  
                                {  
                                thefile.writeln(info[j]);  
                                }  
                                thefile.close();  
                              }
                              alert('Export Complete');
                              }
                              else{
                              alert('Export Aborted');
                              }
                              }
                              else{
                              throw new Error('There are no documents open!');
                              }
                            }
                            catch(e) {
                              alert( e.message, "Script Alert", true);
                            }
                            
                            • 11. Re: Re: Export of color values to Excel
                              EWO54 Community Member

                              Wow, you are going over and above  - I really appreciate your help.  I update the script with the data you provided and ran the script using my Mac script editor and i got an error message that said, "Error on line 62: ReferenceError: Can't find variable: alert"  This is the last line of the script.  I saved it and tried to run the script in Illustrator and again I got no response. 

                              • 12. Re: Re: Export of color values to Excel
                                imagecollection Community Member

                                you can try to delete line 1 "try{"

                                and the last few lines: shown highlighted below.

                                err.JPG

                                 

                                is the Mac script editor you mention the ExtendScript Toolkit.?

                                • 13. Re: Export of color values to Excel
                                  imagecollection Community Member

                                  here is a link to col.jsx

                                  http://ge.tt/66LnIH52/v/0

                                  i just got access to a mac here at work and tried this and it worked fine.

                                  just save the "col.jsx" file to desktop.

                                  open new doc in illustrator. standard print doc should have 64 default swatches.

                                  goto File->Scripts->Other Script...

                                  navigate to desktop and run col.jsx

                                  Folder dialogue should apear, select desktop and press OK.

                                  there should now be an alert saying export complete.

                                  and there should be a untitled.csv on the desktop.

                                  • 14. Re: Export of color values to Excel
                                    EWO54 Community Member

                                    You  are amazing - This script works great!!!  Thanks for all of your time and persistence.  I really appreciate it. 

                                     

                                    EO

                                    • 15. Re: Export of color values to Excel
                                      imagecollection Community Member

                                      no problems.

                                      I made it add id's for all swatches even if they don't have CMYK or RGB values so you keep a total of all swatches.

                                      hope it helps you out.

                                      I learnt a bit in the process which is why I enjoy this.