﻿/*     
author: ferdinand pechmann

This script creates a colour chart  for CMYK colors.
It can be used to print a color chart for your specific printer with a specific paper you might use freqently.
The script can be adjusted by the amount steps per C, M, Y values.

script uses the font :  DIN Next LT Pro
*/



///////////////////////////////////////////////
//choose the gradate detail from 1 to 6 steps per color

var steps_per_Color = 6;

////////////////////////////////////////////////



 
switch(steps_per_Color )
{
case 1:
    var pages_per_doc = 5;
    break;
case 2:
    var pages_per_doc = 22;
    break;
case 3:
    var pages_per_doc = 54;
    break;
case 4:
    var pages_per_doc = 108;
    break;
case 5:
    var pages_per_doc = 190;
    break;
case 6:
    var pages_per_doc = 306;
    break;
default:
     alert ("please choose a number between 1 - 6 for steps_per_color");
};  



//creates new doc
  var pw = 190;
  var ph = 40;   
  var doc = app.documents.add({
                        documentPreferences:{
                            pageHeight:ph,
                            pageWidth:pw,
                            facingPages:false,
                            pagesPerDocument: (pages_per_doc)
                            }
                  });

// start CMYK value
var  C =0;
var  M =0;
var  Y = 0;
var  K = 0;
var color_steps= 100/steps_per_Color;




//loop contains a single page
// creates a new color
//  a colored rectangles,  colored lines, and CMYK value,

for ( var i = 0; i < pages_per_doc; i++ ) {


//selekt a C M Y value 
if ( C < 100 ){
       C = C + color_steps;
        
 }else if ( M < 100 ){
       C = 0;
       M = M + color_steps;
               
  }else if  ( Y < 100 ){
       M = 0;
       Y = Y + color_steps;
                        
  }else {
       C = 100;
       M = 100;
       Y=100;
                  };

                        
//add 5 colors from the createt CMY value by using different K values 

var  K_value = 0;

for ( j = 0; j < 6; j++){
    
        var  cmyk= "C" + C + " M" + M + " Y" + Y + " K" + K_value; 
        var  color_one = doc.colors.add();
                               color_one.properties = {
                               space : ColorSpace.CMYK,
                               colorValue: [ C,M,Y,K_value],
                               name: (cmyk)};

         K_value = K_value +15;
         };


 


//geometricBounds for the grafic elements on the page
for ( k = 0 ; k < 6 ; k++) {
    switch(k)
    {
    case 0:
        var gb_textframe = [28,173,41,180.5]; 
        var gb_rectangle = [0,164,25,190];  
        var gb_gl1 = [26,164,26,190];
        var gb_gl2 = [27,164,27,190];
        var gb_gl3 = [28,164,28,190];
        var gb_gl4 = [29,164,29,190];
        var gb_gl5 = [30,164,30,190];
        K = 0;
        break;
  
    case 1:
        var gb_textframe = [28,146,41,153.5]; 
        var gb_rectangle = [0,137,25,163];  
        var gb_gl1 = [26,137,26,163];
        var gb_gl2 = [27,137,27,163];
        var gb_gl3 = [28,137,28,163];
        var gb_gl4 = [29,137,29,163];
        var gb_gl5 = [30,137,30,163];
        K = 15;
        break;
  
    case 2:
        var gb_textframe = [28,119,41,126.5]; 
        var gb_rectangle = [0,110,25,136];  
        var gb_gl1 = [26,110,26,136];
        var gb_gl2 = [27,110,27,136];
        var gb_gl3 = [28,110,28,136];
        var gb_gl4 = [29,110,29,136];
        var gb_gl5 = [30,110,30,136];
        K = 30;
        break;

    case 3:
        var gb_textframe = [28,92,41,99.5]; 
        var gb_rectangle = [0,83,25,109];  
        var gb_gl1 = [26,83,26,109];
        var gb_gl2 = [27,83,27,109];
        var gb_gl3 = [28,83,28,109];
        var gb_gl4 = [29,83,29,109];
        var gb_gl5 = [30,83,30,109];
        K = 45;
        break;
  
    case 4:
        var gb_textframe = [28,65,41,72.5]; 
        var gb_rectangle =  [0,56,25,82];  
        var gb_gl1 = [26,56,26,82];
        var gb_gl2 = [27,56,27,82];
        var gb_gl3 = [28,56,28,82];
        var gb_gl4 = [29,56,29,82];
        var gb_gl5 = [30,56,30,82];
        K = 60;
        break;
  
    case 5:
        var gb_textframe = [28,38,41,45.5]; 
        var gb_rectangle =  [0,0,25,55];  
        var gb_gl1 = [26,0,26,55];
        var gb_gl2 = [27,0,27,55];
        var gb_gl3 = [28,0,28,55];
        var gb_gl4 = [29,0,29,55];
        var gb_gl5 = [30,0,30,55];
        K = 75;
        break;   
        };

//go to page
var page = doc.pages[i];       

// name of the swatch by CMYK value
var cmyk= "C" + C + " M" + M + " Y" + Y + " K" + K; 

//CMYK value in text
var typocmyk = page.textFrames.add({
                geometricBounds: gb_textframe,
                contents: "C " + C  + "   M " +  M   + "   Y " + Y  + "    K " + K               
                });

// some adjustments to the text
var typocmyk_paragraph = typocmyk.paragraphs.anyItem();                
typocmyk_paragraph.properties = {
                  pointSize: 8,
                  fillColor: doc.swatches.itemByName (cmyk) ,                                            
                  appliedFont:"DIN Next LT Pro",
                  };     
              
//rotate the text
var typocmyk_frames = page.textFrames.firstItem ();                                                                         
var rotate = app.transformationMatrices.add({counterclockwiseRotationAngle:(90)});// rotate 
typocmyk_frames.transform(CoordinateSpaces.pasteboardCoordinates, AnchorPoint.centerAnchor, rotate); 


// make rechtangle with CMYK value
var  rect = page.rectangles.add({
              geometricBounds:gb_rectangle,
              strokeColor: doc.swatches.item(0),
              fillColor: doc.swatches.itemByName (cmyk)
              });
          
// make lines with the CMYK value
var gl1 = page.graphicLines.add({
                geometricBounds:gb_gl1,
                strokeColor: doc.swatches.itemByName (cmyk),
                strokeWeight: (2)
                });
       
var gl2 = page.graphicLines.add({
                geometricBounds:gb_gl2,
                strokeColor: doc.swatches.itemByName (cmyk),
                strokeWeight: (1)
                });
                       
var gl3 = page.graphicLines.add({
                geometricBounds:gb_gl3,
                strokeColor: doc.swatches.itemByName (cmyk),
                strokeWeight: (0.5)
                });
            
var gl4 = page.graphicLines.add({
                geometricBounds:gb_gl4,
                strokeColor: doc.swatches.itemByName (cmyk),
                strokeWeight: (0.3)
                });

var gl5 = page.graphicLines.add({
                geometricBounds:gb_gl5,
                strokeColor: doc.swatches.itemByName (cmyk),
                strokeWeight: (0.1)
                });           
};

};





