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

Adode Illustrator Ledgend Script not working.

New Here ,
Apr 03, 2022 Apr 03, 2022

Hello Guys,

 

I am trying to run the following Script to generate swatch ledgend. I am getting the errod you can see on the screen shot, Can somebody assist me. I tried another simular script but also got the same error. 

 

 

SCRIPT:

 

doc = activeDocument, 

swatches = doc.swatches, 

cols = 4, // number of columns in group 

displayAs = "SPOTColor",  //or "CMYKColor" 

printColors = ["SPOT"], // RGB, CMYK, LAB and/or GrayScale 

textSize = 6, // output text size value in points 

rectRef=null, 

textRectRef=null, 

textRef=null, 

swatchColor=null, 

x=null, 

y=null, 

 

w=16; // width of ellipse

h=16, // height of ellipse

h_pad = 45, //distance between swatches horizontally

v_pad = 10, // distance between swatches vertically

t_h_pad = 55, //width of text box

t_v_pad = 2, //vertical position of text box - more means lower

 

activeDocument.layers[0].locked= false; 

var newGroup = doc.groupItems.add(); 

newGroup.name = "NewGroup"; 

newGroup.move( doc, ElementPlacement.PLACEATBEGINNING ); 

 

for(var c=2,len=swatches.length;c<len;c++) 

    var swatchGroup = doc.groupItems.add(); 

    swatchGroup.name = swatches.name; 

 

    x= (w+h_pad)*((c-2)% cols); 

    y=(h+v_pad)*(Math.round(((c)+.03)/cols))*-1 ; 

    rectRef = doc.pathItems.ellipse(y,x, w,h);  //circle or rectangle

    swatchColor = swatches.color; 

    rectRef.fillColor = swatchColor; 

    rectRef.stroked=false; 

    textRectRef =  doc.pathItems.rectangle(y- t_v_pad,x+ t_h_pad, w-(0.95*t_h_pad),h-(1*t_v_pad));  // padding between ellipse and text box

    textRef = doc.textFrames.areaText(textRectRef);

    textRef.contents = swatches.name; 

    textRef.textRange.size = textSize; 

    rectRef.move( swatchGroup, ElementPlacement.PLACEATBEGINNING ); 

    textRef.move( swatchGroup, ElementPlacement.PLACEATBEGINNING ); 

    swatchGroup.move( newGroup, ElementPlacement.PLACEATEND ); 

 

miroslavr12421009_0-1648974988167.pngexpand imagemiroslavr12421009_1-1648975062029.pngexpand image

 

TOPICS
Scripting , Tools
338
Translate
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
Adobe
Guide ,
Apr 03, 2022 Apr 03, 2022

The index was missing in the loop.  On a separate note, it's good etiquette to keep the credit of the author. 

 

doc = activeDocument, 
swatches = doc.swatches, 
cols = 4, // number of columns in group 
displayAs = "SPOTColor",  //or "CMYKColor" 
printColors = ["SPOT"], // RGB, CMYK, LAB and/or GrayScale 
textSize = 6, // output text size value in points 
rectRef=null, 
textRectRef=null, 
textRef=null, 
swatchColor=null, 
x=null, 
y=null, 
w=16; // width of ellipse
h=16, // height of ellipse
h_pad = 45, //distance between swatches horizontally
v_pad = 10, // distance between swatches vertically
t_h_pad = 55, //width of text box
t_v_pad = 2, //vertical position of text box - more means lower
activeDocument.layers[0].locked= false; 
var newGroup = doc.groupItems.add(); 
newGroup.name = "NewGroup"; 
newGroup.move( doc, ElementPlacement.PLACEATBEGINNING ); 
for(var c=2,len=swatches.length;c<len;c++) { 
    var swatchGroup = doc.groupItems.add(); 
    swatchGroup.name = swatches[c].name; 
    x= (w+h_pad)*((c-2)% cols); 
    y=(h+v_pad)*(Math.round(((c)+.03)/cols))*-1 ; 
    rectRef = doc.pathItems.ellipse(y,x, w,h);  //circle or rectangle
    swatchColor = swatches[c].color; 
    rectRef.fillColor = swatchColor; 
    rectRef.stroked=false; 
    textRectRef =  doc.pathItems.rectangle(y- t_v_pad,x+ t_h_pad, w-(0.95*t_h_pad),h-(1*t_v_pad));  // padding between ellipse and text box
    textRef = doc.textFrames.areaText(textRectRef);
    textRef.contents = swatches[c].name; 
    textRef.textRange.size = textSize; 
    rectRef.move( swatchGroup, ElementPlacement.PLACEATBEGINNING ); 
    textRef.move( swatchGroup, ElementPlacement.PLACEATBEGINNING ); 
    swatchGroup.move( newGroup, ElementPlacement.PLACEATEND ); 
}

 

Translate
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
Community Expert ,
Apr 03, 2022 Apr 03, 2022
Translate
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 ,
Apr 03, 2022 Apr 03, 2022
LATEST

Thank you Sirs, for the help. Now it works.

 

Appolagies to the original author i found the script on reddit post without much of a info about this.

 

 

https://www.reddit.com/r/AdobeIllustrator/comments/aeisbh/illustrator_swatch_legend_generator_script...

Translate
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