Illustrator_Javascript




==================IMPORT_A_CSV_FILE=============================================


1) Load a Template file

2) Call OpenDialog for just CSV files

3) Import full file as text into dataBase

4) Read each line using readln() into str

5) Split into words using comma

6) Reconstruct line into str2 using spaces 

7) Append all str2 to str3

8) Output str3 as point text 

9) Output text available as cut and paste


  var Separator = ';';

  var NextLine = '\\n';

  var dataBase;

  var str3 = " ";


  var filePath              ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var thisDoc               = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                   alert ( "open a template")

//========================================================

  if                          ( Folder.fs == "Macintosh" ) 

{ dataBase                  = File.openDialog( "Open CSV Data", fileFilter );

  dataBase                  = new File( dataBase.fsName ); 

}

  dataBase.open(              "read")

  redraw();                   alert ( "Open A CSV File")

//========================================================

  dataFlow                  = true;

  while(                      dataFlow) 

{ var str                   = dataBase.readln();

  var str2                  = " ";

  if                          (str) 

{ values                    = str.split(',');

  for                         (i=0;i<values.length;i++) 

{ str2                      = str2 +  "      " +values[i];

} str3                      = str3  + str2 + "\r";

} else 

{ dataFlow                  = false;

  continue;

}

} redraw();                   alert ( "Add Spacings")

//========================================================

  var pointTextRef          = thisDoc.textFrames.add();         // Point Text

  pointTextRef.contents     = str3;

  pointTextRef.top          = 700;

  pointTextRef.left         = 100;

  pointTextRef.selected     = true;

  redraw();                   alert ( "Use_Point_For_Text")

//========================================================

  

  function                    fileFilter( f )

{ var Extension             = ".csv";

  var lCaseName             = f.name;

  lCaseName.toLowerCase();

  if                          ( lCaseName.indexOf( Extension ) == (f.name.length - Extension.length) ) return true;

  else if                     ( f.type == "TEXT" ) return true;

  else if                     ( f instanceof Folder ) return true;

  else return                 false;

}



====================EXTRACT_XY_POINTS_FROM_A_DRAWING======================


1) Draw an object in a document

2) Select just that object

3) Run extaction script

4) Will extract all anchor XY data 

5) Will format into arraylist as javascript array format

6) Output arraylist into a textframe

7) Text in textframe is available for copy and paste

   

// Create path and select it before running point extraction


  var docRef                = app.activeDocument;

  var teststr               = "The Path Data \r";

  var arrayList             = "List for array  \n";

  for                        ( i = 0; i < docRef.pathItems.length; i++ )

{ for                        ( j = 0; j < docRef.pathItems[i].pathPoints.length; j++ )

{ arrayList                += "\n" + " new Array(" + docRef.pathItems[i].pathPoints[j].anchor +"), \r";

}

}

 //========================================================

  var rectObj               = docRef.pathItems.rectangle(300, 20, 180, 220);  //    (y, x, w, h)

  var areaText              = docRef.textFrames.areaText(rectObj);

  redraw();                   alert ( "CreateBoxForText" ) 

//======================================================== 

  areaText.contents         = arrayList;

  redraw();                   alert ( "Can Copy From This Text")

//======================================================== 




=================CREATE_AND_SELECT_PAGEITEMS_AND_USE_MATRIX==================


1) Load a Template file

2) Create a rectangle, an ellipse, a polygon, and a star 

3) Create a text line called textRef2

4) Select textRef2

5) Find and select all pathItems

6) List all pathItems

7) Find and use Matrix to rotate all pageItems

8) Find and list all selected Items



  


  var filePath            ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var thisDoc             = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                 alert ( "open a template")

//========================================================

  var artLayer            = thisDoc.layers[0];

  app.defaultStroked      = true;

  app.defaultFilled       = true;

  var rect                = artLayer.pathItems.rectangle( 762.5, 87.5, 425.0, 75.0 );

  redraw();                 alert ( "Create Rectangle"  )

//========================================================

  var ellipse             = artLayer.pathItems.ellipse(  512.5, 87.5, 425.0, 75.0, false, true ); 

  redraw();                 alert ( "Create Ellipse" )

//========================================================

  var octagon             = artLayer.pathItems.polygon( 300.0, 325.0, 75.0, 8 );     // Create octagon, and 8-sided polygon

  redraw();                 alert ( "Create Polygon  "   )

//========================================================

  var star                = artLayer.pathItems.star( 300.0, 125.0, 100.0, 20.0, 4 );   // Create a 4 pointed star

  redraw();                 alert ( "Create star"  )

//========================================================

  var textRef2            = thisDoc.textFrames.add();

  textRef2.contents       = "textRef2";

  textRef2.top            = 600;

  textRef2.left           = 200;

  textRef2.textRange.characterAttributes.size = 20;

  redraw();                 alert ( "Create Text2  "   )

//======================================================== 

  textRef2.selected       = true;

  redraw();                 alert ( "Select Text2  "   )

//======================================================== 

  msgType                 = "Path items: \n";

  count                   = 0;

  if                       ( thisDoc.pathItems.length > 0 ) 

{ thePaths                = thisDoc.pathItems;

  numPaths                = thePaths.length;

  for                       ( i = 0; i < thisDoc.pathItems.length; i++ ) 

{ pathArt                 = thisDoc.pathItems[i];

  msgType                += "\nItem " + i + " typename is: " + pathArt.typename;

  if                        ( pathArt.parent.typename != "CompoundPathItem" ) 

{ pathArt.selected        = true;

  count++;

}

}

}

  redraw();                 alert ( msgType  )

//========================================================

  var moveMatrix          = app.getTranslationMatrix( 0.5, 1.5 );

  var totalMatrix         = concatenateRotationMatrix( moveMatrix, 10 );// Add rot to trans, 10 degr cclockw

  for                       ( i = 0; i < thisDoc.pageItems.length; i++ ) 

{ thisDoc.pageItems[i].transform( totalMatrix );

  pathArt                 = thisDoc.pageItems[i];

  msgType                 = "Rotate Item " + i + " typename is: " + pathArt.typename;

  redraw();                 alert ( msgType  )

//========================================================

}

  mySelection             = app.activeDocument.selection;

  msgType                 = "Selection items: \n";

  for                       (var i=0; i<mySelection.length; i++)

{ msgType                += "\nItem " + i + " typename is: " + mySelection[i].typename;

}

  redraw();                 alert ( msgType  )

//========================================================

  var docRef              = activeDocument;

  docRef.selection        = null;

  redraw();                 alert ( "DeSelect All "   )

//========================================================

  aiDocument              = app.activeDocument;

  aiDocument.close(         SaveOptions.DONOTSAVECHANGES );

  alert (                  "DONOTSAVECHANGES " )

 //======================================================== 



 

===================DUPLICATES_SELECTED_TO_NEW_DOCUMENT====================


1) Select objects to copy in an open file

2) Run the duplicate program

3) Will create a new document

4) Will duplicate all selected item into the new document


  


// Duplicates selected  from active document into  new document.


  var newItem;

  var docSelected         = app.activeDocument.selection;

  if                        ( docSelected.length > 0 ) 

{ var newDoc              = app.documents.add();     // Create new document move selected items to it.

  redraw();                 alert ( "Create NewDoc"  )

  if                        ( docSelected.length > 0 ) 

{ for                       ( i = 0; i < docSelected.length; i++ ) 

{ docSelected[i].selected = false;

  newItem                 = docSelected[i].duplicate( newDoc, ElementPlacement.PLACEATEND );

  redraw();                 alert ( "Duplicate all selections"  )

}

}

  else 

{ docSelected.selected    = false;

  newItem                 = docSelected.parent.duplicate( newDoc, ElementPlacement.PLACEATEND );

}

}

  else {                    alert( "Please select one or more art objects" );}





===================TEXT_ON_PATHS=================================


1) Load a Template file

2) Do a areaTextInRectangle() function 

3) Do a pointText()           function 

4) Do a textOnLinePath()      function 

5) Do a textOnHalfCircle()    function 


     


  // Text_on_Path

  //docPreset.width = 1191.0;

  //docPreset.height = 842.0

  //var thisDoc = app.documents.add( DocumentColorSpace.RGB , 1191,842);

  //var thisDoc            = app.documents.add( DocumentColorSpace.RGB );

  //redraw();                alert ( "app.documents.add( DocumentColorSpace.RGB )" ) 


  var filePath           ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var thisDoc            = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                alert ( "open a template")

  //========================================================

  areaTextInRectangle();   redraw();        alert ( "areaTextInRectangle() is done " ) ;

  //========================================================

  pointText();             redraw();        alert ( "pointText() is done " ) ;

  //========================================================

  textOnLinePath();        redraw();        alert ( "textOnLinePath() is done " ) ;

  //========================================================

  textOnHalfCircle();      redraw();        alert ( "textOnHalfCircle() is done" ) 

  //======================================================== 

  aiDocument             = app.activeDocument;

  aiDocument.close(        SaveOptions.DONOTSAVECHANGES );

  alert (                  "aiDocument.close( SaveOptions.DONOTSAVECHANGES )" )

  

  function                 areaTextInRectangle()

{ var rectObj            = thisDoc.pathItems.rectangle(500, 200, 220, 220);  //    (x, y, w, h)

  redraw();                alert ( "thisDoc.pathItems.rectangle(600, 200, 100, 120)" ) 

  //========================================================

  var areaText           = thisDoc.textFrames.areaText(rectObj);

  redraw();                alert ( "thisDoc.textFrames.areaText(rectObj)" ) 

  //========================================================

  areaText.contents     = "This is an Area Text in a rectangle. See how it flows to the next line.";

  redraw();                alert ( "This is an Area Text in a rectangle. See how it flows to the next line." )

  //========================================================

  applyTextFormats(        areaText);

  redraw();                alert ( "applyTextFormats(areaText)" )

}

  function                 textOnLinePath()

{ var lineObj            = thisDoc.pathItems.add();

  redraw();                alert ( "thisDoc.pathItems.add()" ) 

  //========================================================

  lineObj.setEntirePath(   Array(Array(100, 300), Array(400, 200)  ) );

  redraw();                alert ( "lineObj.setEntirePath( Array(Array(200, 400), Array(300, 300)  )" )

  //========================================================

  var linePathText       = thisDoc.textFrames.pathText(lineObj);

  redraw();                alert ( "thisDoc.textFrames.pathText(lineObj)" ) 

  //========================================================

  linePathText.contents = "This is text on a line pathItem.";

  redraw();                alert ( "This is text on a line pathItem." ) 

  //========================================================

  applyTextFormats(        linePathText);

  redraw();                alert ( "applyTextFormats(areaText)" )

  //========================================================

}

  function                 pointText()

{ var pointText          = thisDoc.textFrames.add();

  redraw();                alert ( "thisDoc.textFrames.add" ) 

  //========================================================

  pointText.contents     = "This is a point text.";

  redraw();                alert ( "thisDoc.pathItems.add()" ) 

  //========================================================

  pointText.top          = 150;

  redraw();                alert ( "pointText.top = 150" )

  //========================================================

  pointText.left         = 200;

  redraw();                alert ( "pointText.left = 200" ) 

  //========================================================

  applyTextFormats(        pointText);

  redraw();                alert ( "applyTextFormats(areaText)" )

  //========================================================

}

  function                 textOnHalfCircle()

{ var theCircle          = thisDoc.pathItems.ellipse( 750, 200, 300, 300 );    // top, left, width, height

  redraw();                alert ( "thisDoc.pathItems.ellipse( 750, 200, 250, 250 )" ) 

  //========================================================

  var lastPoint          = theCircle.pathPoints.length-1;                      // convert ellipse to half-ellipse 

  theCircle.pathPoints[    lastPoint].remove();                              // Delete last point make semi circle

  //========================================================

  redraw();                alert ( "theCircle.pathPoints[lastPoint].remove()" ) 

  //========================================================

  theCircle.closed       = false;                                              // path open  is a half circle

  redraw();                alert ( "theCircle.closed " + theCircle.closed) 

  //========================================================

  var halfCirclePath     = theCircle.pathPoints;                              // can obtain  path points  if needed

  var str                = "";

  for                      (var i= 0; i < halfCirclePath.length ; i++)

  { str                  = str +" "+halfCirclePath[i].leftDirection+" "+halfCirclePath[i].rightDirection +"\r"

  }

  redraw();                alert ( "halfCirclePath = \r" + str ) 

  //========================================================

  var circleText        = thisDoc.textFrames.pathText(theCircle, 400, 750, TextOrientation.HORIZONTAL);  // write text pathItem

  circleText.textPath   = theCircle;

  circleText.contents   = "This is an example of text on a half ellipse pathItem.";

  redraw();                alert ( "circleText.contents = " + circleText.contents ) 

  //========================================================

  circleText.kind       = "pathText";                                      

  redraw();                alert ( "circleText.kind = " + circleText.kind) 

  //========================================================

  circleText.name       = "Path 1"; 

  redraw();                alert ( "circleText.name =  "+ circleText.name ) 

  //========================================================

  circleText.closed     = false;

  redraw();               alert ( "circleText.closed" ) 

  //========================================================

  applyTextFormats(       circleText);                                // Set other attributes like center align, size is 14 etc.

  redraw();               alert ( "applyTextFormats(circleText)" ) 

  //========================================================

}

  function                                      applyTextFormats(thisText)

{ thisText.spacing                            = 10;

  thisText.paragraphs[0].justification        = Justification.CENTER;

  thisText.textRange.characterAttributes.size = 24;

}


==================SELECT_MOVE_SCALE_ROTATE=======================


1) Load a Template file

2) Do a create a group 

3) Draw trianglePath within the group

4) Stroke but don’t close the trianglePath

5) Extract all pathItems into thePaths 

6) Define pathArt as the first item in thePaths

7) Select pathArt

8) Translate, resize, flip, and rotate pathArt



  


  var filePath              = "/Users/don_sauer/Downloads/adobe/illustrator/612X792px.ait"

  var docRef                = open(new File( filePath ))             //var docRef = documents.add();

  redraw();                   alert ( "open a template")

//========================================================

  var triangleGroup         = app.activeDocument.groupItems.add();

  var trianglePath          = triangleGroup.pathItems.add();

  trianglePath.setEntirePath( Array( Array(100, 100), Array(300, 100), Array(200, 200 ) ));

  redraw();                   alert ( "Path_from_XY_points ")

//========================================================

  trianglePath.closed        = false;

  trianglePath.stroked       = true;

  trianglePath.filled        = false;

  trianglePath.strokeWidth   = 3;

  redraw();                    alert ( "Stroke ")

//========================================================

  thePaths                   = docRef.pathItems;

  numPaths                   = thePaths.length;

  pathArt                    = docRef.pathItems[0];

  pathArt.selected           = true; 

  redraw();                    alert ( "Selected ")

//========================================================

  pathArt.translate(           30, 100);          //rotate clockwise 90 degrees

  redraw();                   alert ( "move 30, 100 ")

//========================================================

  pathArt.resize(             50 , 150);          //rotate clockwise 90 degrees

  redraw();                   alert ( "scale 50,150 ")

//========================================================

  pathArt.resize(             -100 , 100);          //rotate clockwise 90 degrees

  redraw();                   alert ( "scale -100,100 ")

//========================================================

  pathArt.rotate(             30);          //rotate clockwise 90 degrees

  redraw();                   alert ( "rotate 30 degree ")

//========================================================

  pathArt.selected          = false; 



=====================APPLY_TEXT_STYLE===============================


1) Add a new Document

2) Add three textFrames 

3) Create A characterStyle 

4) Apply the characterStyle one by one to each textFrames 


   

  var docRef              = documents.add();

  var textRef1            = docRef.textFrames.add();

  textRef1.contents       = "Scripting is fun!";

  textRef1.top            = 700;

  textRef1.left           = 50;

  redraw();                 alert ( "Add textRef1 "  + textRef1.contents )

  //========================================================

  var textRef2            = docRef.textFrames.add();

  textRef2.contents       = "Scripting is easy!";

  textRef2.top            = 625;

  textRef2.left           = 100;

  redraw();                 alert ( "Add textRef2 " + textRef2.contents   )

  //========================================================

  var textRef3            = docRef.textFrames.add();

  textRef3.contents       = "Everyone should script!";

  textRef3.top            = 550;

  textRef3.left           = 150;

  redraw();                 alert ( "Add textRef3 " + textRef3.contents   )

  //========================================================

  var charStyle           = docRef.characterStyles.add("BigRed");  // Create a new character style

  redraw();                 alert ( "Add a CharacterStyle " + charStyle   )

  //========================================================

  var charAttr            = charStyle.characterAttributes;           // set character attributes

  charAttr.size           = 40;

  charAttr.tracking       = -50;

  charAttr.capitalization = FontCapsOption.ALLCAPS;

  redraw();                 alert ( "Create characterAttributes " + charAttr   )

  //========================================================

  var redColor            = new RGBColor();

  redColor.red            = 255;

  redColor.green          = 0;

  redColor.blue           = 0;

  charAttr.fillColor      = redColor;

  charAttr.textFont       = app.textFonts[4]

  charStyle.applyTo(        textRef1.textRange);     // apply to each textFrame in the document

  redraw();                 alert ( "applyTo textRef1 "    )


  charStyle.applyTo(        textRef2.textRange);

  redraw();                 alert ( "applyTo textRef2"    )

  charStyle.applyTo(        textRef3.textRange);

  redraw();                 alert ( "applyTo textRef3  "     )

  //========================================================

  aiDocument              = app.activeDocument;

  aiDocument.close(         SaveOptions.DONOTSAVECHANGES );

  alert (                   "Close_Don't_Save" )

 //======================================================== 



=================ENLARGE_FIRST_LETTER_EACH_WORD==========================


1) Load a Template file

2) Create a textFrames 

3) Use text.words[j] to find each word

4) Use textWord.characters[0] to find the first letter

5) Resize that letter


   

  // Changes size of the first character of each word in the

  var filePath           ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef             = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                alert ( "open a template")

  //========================================================

  var pointTextRef       = docRef.textFrames.add();         // Point Text

  pointTextRef.contents  = "TextFrame #3 point";

  pointTextRef.top       = 700;

  pointTextRef.left      = 200;

  pointTextRef.selected  = true;

  pointTextRef.textRange.characterAttributes.size = 24;

  redraw();               alert ( "pointText At 400 700 ")

  //========================================================

  for                     ( i = 0; i < app.activeDocument.textFrames.length; i++ ) 

{ text                   = app.activeDocument.textFrames[i].textRange;

  for                     ( j = 0 ; j < text.words.length; j++ ) 

{ textWord               = text.words[j];                   //each word is a textRange object

  firstChars             = textWord.characters[0];

  firstChars.size        = firstChars.size * 1.5;    // Get the first character of each word and increase it’s size

  redraw();                alert ( "Enlarge_First_Letters")

  //========================================================

}

}


=================COLOR_ANY_THE_WORD==========================


1) Load a Document that has textframe in it

2) Loop thru all textFrames call textArt

3) Convert TextArt to a word array called word 

4) If contest of word is “the” color it red


  


  if                  ( app.documents.length > 0 && app.activeDocument.textFrames.length > 0 )

{ wordColor          = new RGBColor();

  wordColor.red      = 255;

  wordColor.green    = 0;

  wordColor.blue     = 255;

  searchWord1        = "the";

  searchWord2        = "The";

  searchWord3        = "THE";

  for                  ( i = 0; i < app.activeDocument.textFrames.length; i++ ) 

{ textArt            = activeDocument.textFrames[i];

  for                  ( j = 0; j < textArt.words.length; j++) 

{ word               = textArt.words[j];

  if                   ( word.contents == searchWord1 || word.contents == searchWord2 || word.contents == searchWord3 ) 

{ word.filled        = true;

  word.fillColor     = wordColor;

}

}

}

}






=================TEXT_USING_AREA_OR_LINE_OR_POINT========================


1) Load a Template file

2) Create a textFrames which use area, line, or point

3) Change the text in each textFrames


  


  var filePath           ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef             = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                alert ( "open a template")

  //========================================================

  var rectRef            = docRef.pathItems.rectangle(700, 50, 100, 100);

  var areaTextRef        = docRef.textFrames.areaText(rectRef);

  areaTextRef.contents   = "TextFrame #1 area";

  areaTextRef.selected   = true;

  redraw();                alert ( "Create_Rect_For_Text")

  //========================================================

  var lineRef            = docRef.pathItems.add();         // Line Text

  lineRef.setEntirePath(   Array(Array(200, 700), Array(300, 550) ) );

  var pathTextRef        = docRef.textFrames.pathText(lineRef);

  pathTextRef.contents   = "TextFrame #2 Line ";

  pathTextRef.selected   = true;

  redraw();                alert ( "Create_Line_for_Text")

  //========================================================

  var pointTextRef       = docRef.textFrames.add();         // Point Text

  pointTextRef.contents  = "TextFrame #3 point";

  pointTextRef.top       = 700;

  pointTextRef.left      = 400;

  pointTextRef.selected  = true;

  redraw();               alert ( "Use_Point_For_Text")

  //========================================================

  var iCount             = docRef.textFrames.length;

  var sText              = "There are " + iCount + " TextFrames.\r"

  sText                 += "Changing contents of each TextFrame.";

  docRef.textFrames[0].contents = "Area TextFrame.";

  docRef.textFrames[1].contents = "Path TextFrame.";

  docRef.textFrames[2].contents = "Point TextFrame.";

  redraw();                alert ( "Changing contents of each TextFrame")

  //========================================================

  docRef.textFrames[1].remove();

  redraw();                alert ( "remove textFrames[1]")

  //========================================================// count again

  var iCount = docRef.textFrames.length;

  redraw();                alert ( "iCount = " + iCount )

  //========================================================




====================DUPLICATE_AND_ROTATE================================


1) Load a Template file

2) Create a pointText textFrames called pointTextRef

3) Select pointTextRef

4) Create a textContainer which is a copy of pointTextRef

5) Duplicate and rotate the copies  


   

  var filePath           ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef             = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                alert ( "open a template")

  //========================================================

  var pointTextRef       = docRef.textFrames.add();

  pointTextRef.contents  = "point text";

  pointTextRef.top       = 200;

  pointTextRef.left      = 400;

  pointTextRef.selected  = true;

  pointTextRef.textRange.characterAttributes.size = 24;

  redraw();                alert ( "pointText 200 400 ")

  //========================================================

  selectedItems         = app.activeDocument.selection;

  if                       (selectedItems.length > 0 ) 

{ if                       (selectedItems[0].typename == "TextFrame" ) 

{ dupSrc                 = selectedItems[0];

  textContainer          = dupSrc.parent;

  redraw();                alert ( "Have a Selected TextFrame ")

  //========================================================

  for                      (i = 1; i <= 3; i++ ) 

{ dupText                = dupSrc.duplicate( textContainer, ElementPlacement.PLACEATEND );

  dupText.rotate(          180 * i/6);

  redraw();                alert ( "Duplicate and Rotate ")

} //for                    ( i = 1; i <= 3; i++ )

} //if                     (selectedItems[0].typename == "TextFrame" )

} //if                     (selectedItems.length > 0 ) 




======================VIEW_ALL_PATH_DATA===============================


1) Load a Template file

2) Create a drawing called trianglePath

3) Select pointTextRef

4) Extract all pathItems into thePaths

5) Select the first object as pathArt

6) Extract all pathItems and pathPoints data from pathArt



   



  var filePath              = "/Users/don_sauer/Downloads/adobe/illustrator/612X792px.ait"

  var docRef                = open(new File( filePath ))             //var docRef = documents.add();

  redraw();                   alert ( "open a template")

//========================================================

  var triangleGroup         = app.activeDocument.groupItems.add();

  var trianglePath          = triangleGroup.pathItems.add();

  trianglePath.setEntirePath( Array( Array(100, 100), Array(300, 100), Array(200, 200 ) ));

  redraw();                   alert ( "Path_from_XY_points ")

//========================================================

  trianglePath.closed        = false;

  trianglePath.stroked       = true;

  trianglePath.filled        = false;

  trianglePath.strokeWidth   = 3;

  redraw();                    alert ( "Stroke ")

//========================================================

  thePaths                   = docRef.pathItems;

  numPaths                   = thePaths.length;

  pathArt                    = docRef.pathItems[0];

  pathArt.selected           = true; 

  redraw();                    alert ( "Selected ")

//========================================================

  var teststr               = "The Path Data \r";

  for                        ( i = 0; i < docRef.pathItems.length; i++ )

{ for                        ( j = 0; j < docRef.pathItems[i].pathPoints.length; j++ )

{ teststr                   = teststr + "path="+i+" point="+j+" type="          +docRef.pathItems[i].pathPoints[j].pointType      +"\r";

  teststr                   = teststr + "path="+i+" point="+j+" anchor="        +docRef.pathItems[i].pathPoints[j].anchor         +"\r";

  teststr                   = teststr + "path="+i+" point="+j+" leftDirection=" +docRef.pathItems[i].pathPoints[j].leftDirection  +"\r";

  teststr                   = teststr + "path="+i+" point="+j+" rightDirection="+docRef.pathItems[i].pathPoints[j].rightDirection +"\r";

}

}

  redraw();                   alert ( teststr )

//========================================================



====================PLOT_AND_PRINTOUT_XY_ARRAYS=====================


1) Load a Template file

2) Create any curve as a XY array called lineList

3) Format  lineList array into a javascript readable text call arrayList 

4) Use lineList as a pathItem

5) Output arrayList as a textFrame



    


  var filePath              = "/Users/don_sauer/Downloads/adobe/illustrator/612X792px.ait"

  var docRef                = open(new File( filePath ))             //var docRef = documents.add();

  redraw();                   alert ( "open a template")

//========================================================

  var lineList              = new Array(10);

  for                         ( i = 0; i < lineList.length; i++ ) 

{ lineList[i]               = new Array( i * 10 + 50, i*i*2 +50);

}

  redraw();                   alert ( "Create XY Arrays")

//========================================================

  var arrayList             = "List for array  \r";

  for                         ( i=0 ; i < lineList.length ; i++)      

{ arrayList                += "\n" + " new Array(" + lineList[i]+"), \r"; }

//arrayList                += "\n" + i + " :" + lineList[i]; }

  redraw();                   alert ( arrayList)

//======================================================== 

  newPath                   = app.activeDocument.pathItems.add();

  newPath.filled            = false;

  newPath.stroked           = true;      // Set stroke and width properties of the compound path

  newPath.strokeWidth       = 3.5;

  newPath.setEntirePath(      lineList);

  redraw();                   alert ( "Draw Array")

//========================================================

  var rectObj               = docRef.pathItems.rectangle(500, 200, 220, 220);  //    (x, y, w, h)

  var areaText              = docRef.textFrames.areaText(rectObj);

  redraw();                   alert ( "CreateBoxForText" ) 

//======================================================== 

  areaText.contents         = arrayList;

  redraw();                   alert ( "Can Copy From This Text")

//======================================================== 


===============================================================


  aiDocument                = app.activeDocument;

  aiDocument.close(           SaveOptions.DONOTSAVECHANGES );

  alert (                    "Close_Don't_Save" )

 //======================================================== 




========================PIXEL_DETAILS====================================


1) Template file 612X792px.ait is all in pixel units

2) Line data for LinePath is all in pixel units 

3) The Rulers and dimensions are shown below


   


  var filePath              = "/Users/don_sauer/Downloads/adobe/illustrator/612X792px.ait"

  var docRef                = open(new File( filePath ))             //var docRef = documents.add();

  redraw();                   alert ( "open a template")

//========================================================

  var LineGroup             = app.activeDocument.groupItems.add();

  var LinePath              = LineGroup.pathItems.add();

  LinePath.setEntirePath(     Array( Array(40, 60), Array(80, 100) ));

  redraw();                   alert ( "Path_from_XY_points ")

//========================================================

  LinePath.closed           = false;

  LinePath.stroked          = true;

  LinePath.filled           = false;

  LinePath.strokeWidth      = 3;

  redraw();                   alert ( "Stroke ")

//========================================================

  var Color2                 = new RGBColor;

  Color2.red                 = 255;

  Color2.green               = 0;

  Color2.blue                = 0;

  LinePath.strokeColor       = Color2;

  redraw();                    alert ( "change colors")

//======================================================== 

  aiDocument                = app.activeDocument;

  aiDocument.close(           SaveOptions.DONOTSAVECHANGES );

  alert (                    "Close_Don't_Save" )

 //======================================================== 





===============CIRCLE_LEFT_RIGHT_DIRECTION_POINTS=====================


1) This uses the main() start point

2) An unlocked layer to an open document is needed

3) The use of a Script Prompt is demonstrated

4) Arrays anch(), ldir() and rdir() come from math

5) PathItem pi receives values for anchor, leftDirection, and rightDirection

6) The datapoint anch(), rdir() and ldir() are also plotted in green, red, and blue


  


// Circle


// draws a circle with specified number of anchor points.


  var mpi                = Math.PI;

  var hpi                = mpi / 2;

  var wpi                = mpi * 2;

  var ver10              = (version.indexOf('10') == 0);

  var anch               = new Array; 

  var rdir               = new Array;

  var ldir               = new Array;


main();


function                   main()

{ if                       (documents.length < 1){ return;  }

  with(                    activeDocument.activeLayer )

{ if                       (locked || ! visible)

{ alert(                  "Please select an unlocked and visible layer,\nthen run this script again.");

  return;

}

}

  var number_of_anchors  = 4;            // (default)

  var radius             = 50;

  if                       (! ver10 )    // strue since  ver10 is false

{ number_of_anchors      = prompt("number of anchors", number_of_anchors);

  if                       (!number_of_anchors || isNaN( number_of_anchors ) || number_of_anchors < 2)

{ return;

}

  number_of_anchors      = parseInt( number_of_anchors ); //######################

}

  //redraw();              alert ( "number_of_anchors =  " + number_of_anchors )

  //========================================================

  var                       handle_length, theta;

  if                        (number_of_anchors == 2)

{ handle_length           = radius * 4 / 3;

  theta                   = mpi;

} else 

{ theta                   = wpi / number_of_anchors;

  handle_length           = radius * 4 / 3 * (1 - Math.cos(theta / 2)) / Math.sin(theta / 2);

}

  //redraw();               alert ( "theta =  " + theta + "\r handle_length =  " + handle_length )

  //========================================================

  var pi                  = activeDocument.activeLayer.pathItems.add();

  var arr;

  for                       (var i = 0; i < number_of_anchors; i++)

{ with(                     pi.pathPoints.add())                        ///####################

{ arr                     = [Math.cos(theta * i), Math.sin(theta * i)];

  anchor                  = [arr[0] * radius, arr[1] * radius];

  arr[0]                 *= handle_length;

  arr[1]                 *= handle_length;

  rightDirection          = [anchor[0] - arr[1], anchor[1] + arr[0]];

  leftDirection           = [anchor[0] + arr[1], anchor[1] - arr[0]];

  anch[i]                 = anchor;

  rdir[i]                 = rightDirection ;

  ldir[i]                 = leftDirection ;

  //redraw();               alert ( "anch[i] =  " + anch[i])

}

}

  // redraw();              alert ( "anch.length =  " + anch.length )

  //======================================================== 

  var doc                 = app.activeDocument;

  var colR                = new RGBColor(); colR.red             = 255; colR.green = 0;    colR.blue = 0;

  var colG                = new RGBColor(); colG.red             = 0;   colG.green = 255;  colG.blue = 0;

  var colB                = new RGBColor(); colB.red             = 0;   colB.green = 0;    colB.blue = 255;

  for                       (i = 0; i < anch.length; i++ )

{ var xyA                 = anch[i];

  var xyR                 = rdir[i];

  var xyL                 = ldir[i];

  var doch                = activeDocument.height;

  var docw                = activeDocument.width;

  var ellipse             = doc.pathItems.ellipse(  doch/2 + xyA[0] +3 ,docw/2 +  xyA[1] -3, 6,  6, false, true );

  ellipse.fillColor       = colG ;

  var ellipse             = doc.pathItems.ellipse(  doch/2 + xyR[0] +3 ,docw/2 +  xyR[1] -3, 6,  6, false, true );

  ellipse.fillColor       = colR ;

  var ellipse             = doc.pathItems.ellipse(  doch/2 + xyL[0] +3 ,docw/2 +  xyL[1] -3, 6,  6, false, true );

  ellipse.fillColor       = colB ;

} var teststr             = "The Path Data \r";

  for                       ( i = 0; i < anch.length; i++ )

{ teststr                 = teststr + " point="+i+" anchor="        + anch[i] +"\r";

  teststr                 = teststr + " point="+i+" leftDirection=" + rdir[i] +"\r";

  teststr                 = teststr + " point="+i+" rightDirection="+ ldir[i] +"\r";

}

  redraw();                 alert ( teststr )

 //========================================================

  with(                     pi)                                       // ###### same as with(Math)

{ closed                  = true;

  filled                  = false;

  stroked                 = true;

  strokeColor             = black();

  strokeWidth             = 1;

}

  with(                     activeDocument)                           //###################

{ pi.translate(             width / 2, height / 2); }                 // ############  translates a path

}


function                    black()

{ var col                 = new GrayColor();

  col.gray                = 100;

  if(ver10)

{ var col2                = new Color();

  col2.gray               = col;

  return                    col2;

}

  return                    col;

}



================SELECT_AND_ROTATE_AND_APPLY_NOCOLOR===================== 


1) Load a Template file

2) Two rectangles are added and filled with color

3) The Top rectangle is then filled with nocolor

4) Both rectangles are selected and rotated


  

  var filePath            = "/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef              = open(new File( filePath ))             //var docRef = documents.add();

  redraw();                 alert ( "open a template")

//========================================================

  var itemRef1            = docRef.pathItems.rectangle(500, 170, 250, 100);

 redraw();                 alert ( "create first rectangle")

//========================================================

  var itemRef2            = docRef.pathItems.rectangle(550, 150, 200, 300);

  redraw();                 alert ( "create second rectangle")

//========================================================

  var rgbColor            = new RGBColor();

  rgbColor.red            = 255;

  itemRef2.fillColor      = rgbColor;

  redraw();                 alert ( "fill rectangle 2 ")

//========================================================

  rgbColor.blue           = 255;

  rgbColor.red            = 0;

  itemRef1.fillColor      = rgbColor;

  redraw();                 alert ( "fill rectangle 1 ")

//========================================================

  var noColor             = new NoColor();

  itemRef2.fillColor      = noColor;

  redraw();                 alert ( "fill rectangle 2 with no color ")

//========================================================

  var iCount              = docRef.pathItems.length

  redraw();                 alert ( "iCount =" + iCount)

//========================================================

  for                      (var i=0; i<iCount; i++) 

{ var graphRef            = docRef.pathItems[i];

  graphRef.selected       = true;

  graphRef.rotate(90);      //rotate clockwise 90 degrees

  redraw();                 alert ( "rotate 90 degree ")

//========================================================


}

  docRef.close(             SaveOptions.DONOTSAVECHANGES );

                            alert ( "document closed")

//========================================================




===========================LAYERS_TEMPLATES=====================================


1) Load a Template file which automatically includes Layer1

2) Add layer Layer2 above it called newlayer

3) Add layer Layer3 above it called newlayer2

4) Rename newlayer2 to “Temp”

5) Loop through all app.documents

6) Find number of layers in each app.documents

7) Move bottom layers to the top

8) Loop through all layers

7) Display layername and it order

8) Find if a layer is called “Temp” and remove it


                        

  var filePath                        ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var doc                             = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                             alert ( "open a template")

//========================================================

  var  newlayer                       = app.activeDocument.layers.add();

  redraw();                             alert ( "add a layer  ")

//========================================================

  var  newlayer2                      = app.activeDocument.layers.add();

  redraw();                             alert ( "add a layer  ")

//========================================================

   newlayer2.name                     = "Temp"

  redraw();                             alert ( "name layer = " +newlayer.name )

//========================================================

  for                                   ( i = 0; i < app.documents.length; i++ ) 

{ var targetDocument                  = app.documents[i];

  var layerCount                      = targetDocument.layers.length;

  redraw();                             alert ( "Count Layers = " + layerCount)

//========================================================


  if                                    (layerCount > 1) 

{ bottomLayer                         = activeDocument.layers[layerCount-1];

  bottomLayer.zOrder(                   ZOrderMethod.BRINGTOFRONT);                 // Moves bottom layer to topmost layer

}

  redraw();                             alert ( "Move bottom layer to top ")

  //========================================================


  for                                   (var ii = layerCount - 1; ii >= 0; ii-- ) 

{ targetLayer                         = targetDocument.layers[ii];

  var layerName                       = new String( targetLayer.name );

  redraw();                             alert ( ii+ ")  layerName = "+ layerName)

  //========================================================

  var layersDeleted = 0;

  if                                    (layerName.indexOf("Temp") == 0 ) 

{ targetDocument.layers[ii].remove();

  layersDeleted++;

  redraw();                             alert ( "Found and removed Temp layer ")

  //========================================================

}

}

}

  redraw();                             alert ( "layersDeleted = " + layersDeleted)

//========================================================

  docRef.close(             SaveOptions.DONOTSAVECHANGES );

                            alert ( "document closed")

//========================================================




=======================TREES========================================


1) Load a Template file

2) Create a pathItems array called piRef

3) Loop thru five unique pathRef to add to piRef

4) Load an EntirePath from a XY array into a pathRef

5) Load a randomize Left Top position into the pathRef

6) Load a randomize Height Width scale into the pathRef

7) Load a randomize new CMYKColor into the pathRef

8) Load a randomize opacity into the pathRef

9) Repeat for four new pathRefs


  


  var filePath           ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef             = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                alert ( "open a template")

  //========================================================

  var piRef              = activeDocument.pathItems;

  for                      ( i = 0; i != 5 ; ++i )          // Make a 5 trees

{ var pathRef            = piRef.add();           // Create the tree shape

  pathRef.setEntirePath(   new Array(

new Array(266.4619140625, 370.3046875),

new Array(269.5244140625, 370.3046875),

new Array(268.9619140625, 377.138671875),

new Array(278.607421875, 375.66015625),

new Array(273.607421875, 381.53515625),

new Array(278.607421875, 380.9921875),

new Array(272.4619140625, 388.59765625),

new Array(278.56640625, 386.91015625),

new Array(272.94140625, 393.53515625),

new Array(278.31640625, 391.91015625),

new Array(272.94140625, 397.8671875),

new Array(276.3369140625, 397.47265625),

new Array(271.94140625, 403.53515625),

new Array(274.607421875, 402.53515625),

new Array(268.9619140625, 411.47265625),

new Array(267.3369140625, 414.47265625),

new Array(265.7119140625, 411.47265625),

new Array(260.54541015625, 402.72265625),

new Array(263.2119140625, 403.72265625),

new Array(258.9619140625, 397.59765625),

new Array(262.2119140625, 398.0546875),

new Array(256.94091796875, 392.16015625),

new Array(262.2119140625, 393.72265625),

new Array(256.69091796875, 387.03515625),

new Array(262.7119140625, 388.59765625),

new Array(256.54541015625, 381.1796875),

new Array(261.54541015625, 381.72265625),

new Array(256.54541015625, 375.84765625),

new Array(266.9619140625, 377.138671875 ) ) ) ;

  redraw();                alert ( "Load  Tree XY points "  )

  //========================================================

  var left               = (Math.random() * 350) + 50; // Move the tree to a random position

  var top                = (Math.random() * 200) + 520;

  pathRef.position       = new Array( left, top );

  redraw();                alert ( " Random Left and Top"  )

  //========================================================

  var scale              = (Math.random() * 1.5) + 0.5; // scale the tree between 50% and 200%

  pathRef.height         = scale * pathRef.height;

  pathRef.width          = scale * pathRef.width;

  pathRef.stroked        = false;                  // No stroke

  redraw();                alert ( " Randon Height and Width"  )

  //========================================================


  var cmykColor          = new CMYKColor();  // create a random CMYK color and assign as the fill color

  cmykColor.cyan         = Math.random() * 100;

  cmykColor.yellow       = Math.random() * 100;

  cmykColor.magenta      = Math.random() * 100;

  pathRef.filled         = true;

  pathRef.fillColor      = cmykColor;

  redraw();                alert ( "Random CMYK Color"  )

  //========================================================

  pathRef.opacity        = Math.random() * 100; // apply a random opacity

  redraw();                alert ( "Random Opacity"  )

  //========================================================

}

  docRef.close(            SaveOptions.DONOTSAVECHANGES );

                           alert ( "document closed")

//========================================================





================ADD_AND_VIEW_CURVE_POINTS================================================


1) Load a Template file

2) Create five point arrays for x and y

3) Create a pathItem call line

4) Load the first two points from x and y into Line

5) Create a pathItem having a PointType.SMOOTH  called newPoint

6) Load the last three points from x and y as anchor,leftdirection, and rightdirection

7) Create lineObj and lineObj2 to show control lines

8) Create five cyan ellipses to show the five point arrays for x and y

9) Select the first pathItem in the document and extract all information to teststr


   


  var filePath              ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var thisDoc               = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                   alert ( "open a template")

  //========================================================

  var x                     = Array( 220, 376, 400, 450, 460);  // p0,p1,p2,p2_L,p2_R

  var y                     = Array( 475, 300, 400, 300, 350);

  var r1                    = 8;

  if                          (app.documents.length > 0 ) 

{ var doc                   = app.activeDocument;

  var line                  = doc.pathItems.add();

  line.stroked              = true;

  line.setEntirePath(         Array( Array(x[0], y[0]), Array(x[1], y[1]) ) );

  redraw();                   alert ( "drawline x[0],y[0]),x[1],y[1]")

  //========================================================

  var newPoint              = doc.pathItems[0].pathPoints.add( PointType.SMOOTH );  // Append another point to the line

  newPoint.pointType        = PointType.SMOOTH;

  newPoint.anchor           = Array(x[2], y[2]);

  newPoint.leftDirection    = Array(x[3], y[3]);

  newPoint.rightDirection   = Array(x[4], y[4]);

  //newPoint.pointType      = PointType.CORNER;

  redraw();                   alert ( "new smooth point at "+ newPoint.anchor )

  //========================================================


  var lineObj               = thisDoc.pathItems.add();

  lineObj.setEntirePath(      Array(Array(x[2], y[2]), Array(x[4], y[4])  ) );

  var lineObj2              = thisDoc.pathItems.add();

  lineObj2.setEntirePath(     Array(Array(x[1], y[1]), Array(x[3], y[3])  ) );

  redraw();                   alert ( "lines P1->P3 and P4->P2 " )

  //========================================================

  var colorRef              = new RGBColor();

  colorRef.red              = 0;

  colorRef.green            = 255;

  colorRef.blue             = 255;

  for                         (i = 0; i < 5; i++ )

{ var ellipse               = doc.pathItems.ellipse(  y[i]+r1/2, x[i]-r1/2, r1,  r1, false, true ); 

  ellipse.fillColor         = colorRef ;

  redraw();                   alert ( "points number = " + i  ) ;

}

  redraw();                   alert ( "all points" )

 //========================================================

  doc.pathItems[0].select   = true;

  var teststr               = "The Path Data \r";

  for                        ( i = 0; i < doc.pathItems.length; i++ )

{ for                        ( j = 0; j < doc.pathItems[i].pathPoints.length; j++ )

{ teststr                   = teststr + "path="+i+" point="+j+" type="          +doc.pathItems[i].pathPoints[j].pointType      +"\r";

  teststr                   = teststr + "path="+i+" point="+j+" anchor="        +doc.pathItems[i].pathPoints[j].anchor         +"\r";

  teststr                   = teststr + "path="+i+" point="+j+" leftDirection=" +doc.pathItems[i].pathPoints[j].leftDirection  +"\r";

  teststr                   = teststr + "path="+i+" point="+j+" rightDirection="+doc.pathItems[i].pathPoints[j].rightDirection +"\r";

}

}

  redraw();                   alert ( teststr )

  //========================================================

   doc.close(                 SaveOptions.DONOTSAVECHANGES );

                              alert ( "document closed")

  //========================================================

}

  


=====================CREATE_AND_VIEW_COMPOUND_PATHS=============================


1) Load a Template file

2) Create a compoundPathItems entry called newCompoundPath

3) Add three EntirePath line pathItems call newPath

4) Set the stroke width to 3.55 and the color to swatches[14]

5) Select newCompoundPath and extract all information to teststr

6) Find the number of pathItems in newCompoundPath



   


  var filePath            = "/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef              = open(new File( filePath ))             //var docRef = documents.add();

  redraw();                 alert ( "open a template")

//========================================================

  doc                     = app.activeDocument;

  newCompoundPath         = doc.activeLayer.compoundPathItems.add();

  redraw();                 alert ( "make a compound path ")

//========================================================

  newPath                 = newCompoundPath.pathItems.add();// Create the path items

  newPath.setEntirePath(    Array( Array(30, 50), Array(30, 100) ) );

  redraw();                 alert ( " add new path  (30, 50), (30, 100)  ")

//========================================================

  newPath                 = newCompoundPath.pathItems.add();

  newPath.setEntirePath(    Array( Array(40, 100), Array(100, 100) ) );

  redraw();                 alert ( "add new Path (40, 100), (100, 100) ")

//========================================================

  newPath                 = newCompoundPath.pathItems.add();

  newPath.setEntirePath(    Array( Array(100, 110), Array(100, 300) ) );

  redraw();                 alert ( "add new Path (100, 110),(100, 300)")

//========================================================

  newPath.stroked         = true;      // Set stroke and width properties of the compound path

  newPath.strokeWidth     = 3.5;

  newPath.strokeColor     = app.activeDocument.swatches[14].color;

  redraw();                 alert ( "Set Stroke Width and Color")

//========================================================

  numCompoundPaths        = docRef.layers[0].compoundPathItems.length;

  redraw();                 alert ( "number compoundpaths " + numCompoundPaths)

  //========================================================

  var numpathItems        = newCompoundPath.pathItems.length;

  redraw();                 alert ( "number pathItems " + numpathItems)

  //========================================================

  var numpathPoints       = newCompoundPath.pathItems[0].pathPoints.length;

  redraw();                 alert ( "number pathItems[0] points " + numpathPoints)

  //========================================================

  var teststr               = "The Path Data is \r";

  for                        ( i = 0; i < newCompoundPath.pathItems.length; i++ )

{ for                        ( j = 0; j < newCompoundPath.pathItems[i].pathPoints.length; j++ )

{ teststr                   = teststr + "path="+i+" point="+j+" type="          

                              +newCompoundPath.pathItems[i].pathPoints[j].pointType      +"\r";

  teststr                   = teststr + "path="+i+" point="+j+" anchor="        

                              +newCompoundPath.pathItems[i].pathPoints[j].anchor         +"\r";

  teststr                   = teststr + "path="+i+" point="+j+" leftDirection=" 

                              +newCompoundPath.pathItems[i].pathPoints[j].leftDirection  +"\r";

  teststr                   = teststr + "path="+i+" point="+j+" rightDirection="

                              +newCompoundPath.pathItems[i].pathPoints[j].rightDirection +"\r";

}

}

  redraw();                   alert ( teststr )

//========================================================

  count                    = 0;

  for                        ( i = 0; i < newCompoundPath.pathItems.length; i++ )

{ pathArt                  = newCompoundPath.pathItems[i];

  pathArt.selected         = true;

  count++;

}

  redraw();                   alert ( "selecting  all paths = " + count )

//========================================================



  docRef.close(             SaveOptions.DONOTSAVECHANGES );

                            alert ( "document closed")

//========================================================



======================CREATE_AND_ROTATE_A_GROUP====================================


1) Load a Template file

2) Create a groupItems entry called triangleGroup

3) Add a pathItems entry called trianglePath to triangleGroup

4) Add three xy points as an EntirePath to trianglePath

5) Set the stroke width to 3 and the color to red

6) Add a textFrames entry called captionText to triangleGroup

7) Rotate the full triangleGroup by 30 degree


    


  var filePath              = "/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef                = open(new File( filePath ))             //var docRef = documents.add();

  redraw();                   alert ( "open a template")

//========================================================

  var triangleGroup         = app.activeDocument.groupItems.add();

  var trianglePath          = triangleGroup.pathItems.add();

  trianglePath.setEntirePath( Array( Array(100, 100), Array(300, 100), Array(200, 200 ) ));

  redraw();                   alert ( "Path_from_XY_points ")

//========================================================

  trianglePath.closed        = true;

  trianglePath.stroked       = true;

  trianglePath.filled        = false;

  trianglePath.strokeWidth   = 3;

  redraw();                    alert ( "close_and_Stroke ")

//========================================================

  var Color2                 = new RGBColor;

  Color2.red                 = 255;

  Color2.green               = 0;

  Color2.blue                = 0;

  trianglePath.strokeColor   = Color2;

  redraw();                    alert ( "change colors")

//========================================================

  var captionText            = triangleGroup.textFrames.add();

  captionText.position       = Array(100, 150);

  captionText.textRange.size = 48;

  captionText.contents       = "A triangle";

  var fillColor              = new RGBColor;

  fillColor.red              = 0;

  fillColor.green            = 255;

  fillColor.blue             = 0;

  captionText.filled         = true;

  captionText.fillColor      = fillColor;

//captionText.character.fillColor = fillColor;

  redraw();                    alert ( "Add_Text")

//======================================================== 

  triangleGroup.selected     = true; 

  triangleGroup.rotate(30);    //rotate clockwise 90 degrees

  triangleGroup.selected     = false; 

  redraw();                    alert ( "rotate 30 degree ")

//======================================================== 

  aiDocument                = app.activeDocument;

  aiDocument.close(           SaveOptions.DONOTSAVECHANGES );

  alert (                    "Close_Don't_Save" )

 //======================================================== 



=====================GRADIENTS================================================


1) Load a Template file

2) Select top layer of layers[0] as layer called artLayer

3) Add a pathItems entry called rect

4) Create gradient structure called myGradient using createGradient();

5) Add myGradient as a fillColor for a docPathItem entry


     

  var filePath              ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var thisDoc               = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                   alert ( "open a template")

  //========================================================

  var artLayer              = thisDoc.layers[0];

  var rect                  = artLayer.pathItems.rectangle( 762.5, 87.5, 425.0, 75.0 );

  redraw();                   alert ( "rectangle(T=762.5,L=87.5,W=425.0,H=75.0 )"  )

  //========================================================

  var docPathItems          = app.activeDocument.pathItems;

  redraw();                   alert ( "Items in the document =   "+ docPathItems.length  )

  //========================================================

  var myGradient            = createGradient();   

  redraw();                   alert ( "createGradient "  )

  //========================================================

  for                         ( var i=0; i < docPathItems.length ; i++ )

{ docPathItems[i].filled    = true;                  

  docPathItems[i].fillColor = myGradient;

  redraw();                   alert ( "Fill With myGradient"  )

  //========================================================

} //for                       ( var i=0; i < docPathItems.length ; i++ )

  redraw();                   alert( "Note myGradient in Swatches Palette." );

 //======================================================== 

  aiDocument                = app.activeDocument;

  aiDocument.close(           SaveOptions.DONOTSAVECHANGES );

                              alert ( "Close Don’t Save" )

 //======================================================== 



function                                   createGradient()

{ var startColor                         = new RGBColor();

  var endColor                           = new RGBColor();

  startColor.red                         = 0;

  startColor.green                       = 100;

  startColor.blue                        = 255;

  endColor.red                           = 220;

  endColor.green                         = 0;

  endColor.blue                          = 100;

  var theGradient                        = app.activeDocument.gradients.add(); 

  theGradient.name                       = "myGradient";

  redraw();                                alert ( "Add Gradient Name = " + theGradient.name  )

  //========================================================

  theGradient.type                       = GradientType.LINEAR;

  theGradient.gradientStops[0].rampPoint = 30;  // Modify the first gradient stop

  theGradient.gradientStops[0].midPoint  = 60;

  theGradient.gradientStops[0].color     = startColor;

  theGradient.gradientStops[1].rampPoint = 80; // Modify the last gradient stop

  theGradient.gradientStops[1].color     = endColor;

  var myGradientColor                    = new GradientColor();

  myGradientColor.gradient               = theGradient;

  redraw();                                alert ( "Add Gradient"  )

  //========================================================

  return myGradientColor;

}




======================DUPLICATE_TO_GROUP_AND_APPLY_A_BRUSH===============================


1) Have an open document with a selected pathitem

2) Label selected item as docSelection

3) Create a groupItem entry called called NewGroup

4) Duplicate each item in docSelection and call it newItem 

4) Move each newly created newItem to the beginning of NewGroup

5) Apply brushes[1] to NewGroup


    



// Duplicates and groups all items in the current selection,// then applies the same brush to each item in the group


  if                       ( app.documents.length > 0 ) 

{ docSelection           = app.activeDocument.selection;

  if                       ( docSelection.length > 0 ) 

{ newGroup               = app.activeDocument.groupItems.add();

  redraw();                alert ( "app.activeDocument.groupItems.add"  )

 //======================================================== 

  for                      ( i = 0; i < docSelection.length; i++ ) 

{ newItem                = docSelection[i].duplicate();

  newItem.moveToBeginning( newGroup );

  

} brush4                 = app.activeDocument.brushes[1];

  redraw();                alert ( "app.activeDocument.brushes[1]" + brush4  )

 //======================================================== 

  brush4.applyTo(          newGroup );

}

}



==========================SET_RGB_AND_CMYK=======================================


1) Load a Template file

2) Create a New RGBColor called newRGBColor

3) Apply newRGBColor as an app.activeDocument.defaultFillColor

4) Create a New CMYKCOLOR called cmykColor

5) Apply cmykColor as an app.activeDocument.defaultFillColor


        


  var filePath                        ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef                          = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                             alert ( "open a template")

  //========================================================

  var newRGBColor                     = new RGBColor();   // Define the new color

  newRGBColor.red                     = 255;

  newRGBColor.green                   = 255;

  newRGBColor.blue                    = 0;

  app.activeDocument.defaultFillColor = newRGBColor;

  redraw();                             alert ( "Apply_RGB " + newRGBColor.red +" "+ newRGBColor.green +" "+newRGBColor.blue   )

//========================================================

  var cmykColor                       = new CMYKColor();     // create a random CMYK color and assign as the fill color

  cmykColor.cyan                      = 100;

  cmykColor.yellow                    = 0;

  cmykColor.magenta                   = 0;

  app.activeDocument.defaultFillColor = cmykColor;

  redraw();                             alert ( "IN_CMYK " + cmykColor.cyan +" "+ cmykColor.yellow  +" "+ cmykColor.magenta   )

//========================================================

  aiDocument                          = app.activeDocument;

  aiDocument.close(                     SaveOptions.DONOTSAVECHANGES );

                                        alert ( "Close No Save" )

//======================================================== 



=======================LOAD_RASTER_FILE========================================


1) Load a Template file

2) Create a raster File called rasterFile from a File(jpgFilePath)

3) Create a placeItem entry called myPlacedItem

4) Embed rasterFile into myPlacedItem


   


  var filePath                        ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef                          = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                             alert ( "open a template")

  //========================================================

  var jpgFilePath                     ="/Users/don_sauer/Desktop/Tiger.jpg"

  var rasterFile                      = File(jpgFilePath);

  var myPlacedItem                    = docRef.placedItems.add();

  myPlacedItem.file                   = rasterFile;

  myPlacedItem.position               = Array( 0, docRef.height );

  myPlacedItem.embed();






=========================LIST_SWATCHES============================================




  var doc                   = app.documents.add();

  var swatchesList           = "List for swatchs  \n";

  for                       ( i=0 ; i < doc.swatches.length ; i++)      

{ swatchesList              += "\n" + i + " :" + doc.swatches[i]; }

  alert( swatchesList );


=========================LIST_GRADIENTS============================================


   


  var doc                   = app.documents.add();

  var gradientsList           = "List for gradients  \n";

  for                       ( i=0 ; i < doc.gradients.length ; i++)      

{ gradientsList              += "\n" + i + " :" + doc.gradients[i]; }

  alert( gradientsList );




========================LIST_PATTERNS==============================================


  

  var doc                   = app.documents.add();

  var patternList           = "List of Styles in the current Document: \n";

  for                         ( i=0 ; i < app.activeDocument.patterns.length ; i++)      

{ patternList              += "\n" + i + " :" + app.activeDocument.patterns[i]; }

  alert(                      patternList );




  // Deletes the last pattern from the current document.

  if                         ( app.documents.length > 0 ) 

{ var lastIndex             = app.activeDocument.patterns.length - 1;

  var patternToRemove       = app.activeDocument.patterns[lastIndex];

  var patternName           = patternToRemove.name;

  patternToRemove.remove();  

  patternToRemove           = null;

}



========================LIST_STYLES==============================================


   


  var doc                   = app.documents.add();

  var graphicStylesList     = "List of Styles in the current Document: \n";

  for                         ( i=0 ; i < app.activeDocument.graphicStyles.length ; i++)      

{ graphicStylesList        += "\n" + i + " :" + app.activeDocument.graphicStyles[i]; }

  alert(                      graphicStylesList );




// Duplicates selection into new group, applies graphic style to the new groups items

  if                            ( app.documents.length > 0 ) 

{ var doc                     = app.activeDocument;

  var selected                = doc.selection;

  var newGroup                = doc.groupItems.add();

  newGroup.name               = "NewGroup";

  newGroup.move(                doc, ElementPlacement.PLACEATEND );

  var endIndex                = selected.length;

  for                           ( i = 0; i < endIndex; i++ ) 

{ if                            ( selected[i].typename == "PathItem" )

  selected[i].duplicate(        newGroup, ElementPlacement.PLACEATEND );

}

  for                           ( i = 0; i < newGroup.pageItems.length; i++ ) 

{ doc.graphicStyles[1].applyTo( newGroup.pageItems[i] );

}

}



===========================LIST_BRUSHES===========================================


   


  if                        ( app.documents.length > 0 ) {numberOfBrushes = app.activeDocument.brushes.length; }

  redraw();                 alert ( "numberOfBrushes = " + numberOfBrushes  )

  var docBrushes          = app.activeDocument.brushes;                   //Get brushes available in the current document

  var brushList           = "List of Brushes in the current Document: \n";

  for                       ( i=0 ; i < docBrushes.length ; i++)      

{ brushList              += "\n" + i + " :" + docBrushes[i]; }

  alert( brushList );



===========================LIST_FIRST_20_FONTS====================================


 

  var edgeSpacing            = 20;

  var columnSpacing          = 230;

  var filePath               ="/Users/don_sauer/Downloads/adobe/illustrator/000Template.ait"

  var docRef                 = open(new File( filePath ))    //var docRef = documents.add();

  redraw();                    alert ( "open a template")

//========================================================

  var sFontNames             = "";

  var x                      = edgeSpacing;

  var y                      = (docRef.height - edgeSpacing);

  var iCount                 = textFonts.length;

  for                          (var i=0; i<20; i++) 

{ sFontNames                 = i+") "+textFonts[i].name +" "+ textFonts[i].style;

  redraw();                    alert ( " " + sFontNames )

//========================================================

  var textRef                = docRef.textFrames.add();

  textRef.textRange.characterAttributes.size = 20;

  textRef.contents           = sFontNames;

  textRef.top                = y;

  textRef.left               = x;

//redraw();                    alert ( x+" , " + y )

//========================================================

  textRef.textRange.characterAttributes.textFont = textFonts.getByName(textFonts[i].name);

  redraw();                    alert ( "Apply_Font" )

//========================================================

  y                           -= textRef.height

}




========================LIST_ALL_FONTS_ONE_PAGE================================================


  


// Creates a new A3 sized document and display a list of available fonts until the document is full.


  var edgeSpacing            = 10;

  var columnSpacing          = 230;

  

  var docRef                 = documents.add();

  var sFontNames             = "";

  var x                      = edgeSpacing;

  var y                      = (docRef.height - edgeSpacing);

  var iCount                 = textFonts.length;

  for                          (var i=0; i<iCount; i++) 

{ sFontNames                 = i+")"+textFonts[i].name + textFonts[i].style;

  var textRef                = docRef.textFrames.add();

  textRef.textRange.characterAttributes.size = 10;

  textRef.contents           = sFontNames;

  textRef.top                = y;

  textRef.left               = x;

  if                          ((x + textRef.width)> docRef.width) // check if text frame go off edge

{ textRef.remove();

  iCount                     = i;

  break;

}

  else                       // display text frame

{ textRef.textRange.characterAttributes.textFont = textFonts.getByName(textFonts[i].name);

  redraw();

  if                          ( (y-=(textRef.height)) <= 20 ) 

{ y =                         (docRef.height - edgeSpacing);

  x                         += columnSpacing;

}

}

}


===================================================================================


4-26-13-12-32-08

dsauersanjose@aol.com

Don Sauer