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

Need to edit this script ...Ai ASE Colors & Convert to RGB Values Excel Sheet Script

Explorer ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

 

I am using the script below to extract RGB values in an Ai document using the ASE swatch color and placing each R G B value in a separate column inside a CVS Excel sheet. I want to assign the names of the swatches to the swatche's RGB values instead of the sequenced numbering [Column A = I.D.] that is currectly in the script but I don't know how to do this.

 

Screen Shot 2021-08-17 at 1.59.54 PM.JPG

 

var listfile = "/Users/Name/Desktop/Name.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();  
}  

 

TOPICS
Performance , Scripting

Views

515

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

Guide , Aug 17, 2021 Aug 17, 2021

Are all your swatches named?  Does this do it for you:

 

var listfile = "~/Desktop/Name.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 name1 = col[i].name;
            var c = Math.round(col[i].color.cyan);  
            var m = Math.ro
...

Votes

Translate

Translate
Adobe
Guide ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Are all your swatches named?  Does this do it for you:

 

var listfile = "~/Desktop/Name.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 name1 = col[i].name;
            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(name1+","+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 name2 = col[i].name;
            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(name2+","+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();  
}  

 

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 ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Yes they are named and yes it worked perfectly! You are an wizard! Thank you!!!

 

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
New Here ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

I'm trying to use this scipt to create the same type of list in CMYK. I've changed the listfile path and changed the var doc line to my .ai file and both the .csv file and .ai file open. Getting a script error. Screen shot attached.

NOTE: I'm on Mac OS 12.6 using Script Editor with preferences set to Javascript.

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
Enthusiast ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

LATEST

The Script Editor in Mac OS is not used to write Adobe scripts. That's why you see errors like this. Save the script as .js and run it directly in Adobe Illustrator.

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
New Here ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

I'm trying to create the same type of spreadsheet as the OP but CMYK instead of RGB which it looks like the script is already set up for. I think I'm close to getting it to work but need a few tweaks. See reply to lackostration below.

Thanks!

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