Adobe 65010248 Scripting Guide - Page 46

Combining path point types, Measurement units, on item positioning and dimensions

Page 46 highlights

CHAPTER 5: Scripting with JavaScript Creating paths and shapes 46 var myDoc = app.activeDocument; var myLine = myDoc.pathItems.add(); //set stroked to true so we can see the path myLine.stroked = true; var newPoint = myLine.pathPoints.add(); newPoint.anchor = [220, 475]; //giving the direction points the same value as the //anchor point creates a straight line segment newPoint.leftDirection = newPoint.anchor; newPoint.rightDirection = newPoint.anchor; newPoint.pointType = PointType.CORNER; var newPoint1 = myLine.pathPoints.add(); newPoint1.anchor = [375, 300]; newPoint1.leftDirection = newPoint1.anchor; newPoint1.rightDirection = newPoint1.anchor; newPoint1.pointType = PointType.CORNER; var newPoint2 = myLine.pathPoints.add(); newPoint2.anchor = [220, 300]; //giving the direction points different values //than the anchor point creates a curve newPoint2.leftDirection =[180, 260]; newPoint2.rightDirection = [240, 320]; newPoint2.pointType = PointType.CORNER; Combining path point types The following script sample creates a path with three points: var myDoc = app.activeDocument; var myLine = myDoc.pathItems.add(); myLine.stroked = true; myLine.setEntirePath( [[220, 475], [375, 300]]); // Append another point to the line var newPoint = myDoc.myLine.pathPoints.add(); newPoint.anchor = [220, 300]; newPoint.leftDirection = newPoint.anchor; newPoint.rightDirection = newPoint.anchor; newPoint.pointType = PointType.CORNER; Shapes To create a shape, use the pathItems method that corresponds to the shape's name (like ellipse, rectangle, or polygon), and use the parameters to specify shape's position, size, and other information like the number of sides in a polygon. Remember: ➤ All measurements and page coordinates are processed as points by the scripting engine. For details, see "Measurement units" on page 29. ➤ x and y coordinates are measured from the bottom-left corner of the document, as indicated in the Info panel in the Illustrator application. For details, see "Page-item positioning and dimensions" on page 29.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

C
HAPTER
5: Scripting with JavaScript
Creating paths and shapes
46
var myDoc = app.activeDocument;
var myLine = myDoc.pathItems.add();
//set stroked to true so we can see the path
myLine.stroked = true;
var newPoint = myLine.pathPoints.add();
newPoint.anchor = [220, 475];
//giving the direction points the same value as the
//anchor point creates a straight line segment
newPoint.leftDirection = newPoint.anchor;
newPoint.rightDirection = newPoint.anchor;
newPoint.pointType = PointType.CORNER;
var newPoint1 = myLine.pathPoints.add();
newPoint1.anchor = [375, 300];
newPoint1.leftDirection = newPoint1.anchor;
newPoint1.rightDirection = newPoint1.anchor;
newPoint1.pointType = PointType.CORNER;
var newPoint2 = myLine.pathPoints.add();
newPoint2.anchor = [220, 300];
//giving the direction points different values
//than the anchor point creates a curve
newPoint2.leftDirection =[180, 260];
newPoint2.rightDirection = [240, 320];
newPoint2.pointType = PointType.CORNER;
Combining path point types
The following script sample creates a path with three points:
var myDoc = app.activeDocument;
var myLine = myDoc.pathItems.add();
myLine.stroked = true;
myLine.setEntirePath( [[220, 475], [375, 300]]);
// Append another point to the line
var newPoint = myDoc.myLine.pathPoints.add();
newPoint.anchor = [220, 300];
newPoint.leftDirection = newPoint.anchor;
newPoint.rightDirection = newPoint.anchor;
newPoint.pointType = PointType.CORNER;
Shapes
To create a shape, use the
pathItems
method that corresponds to the shape’s name (like
ellipse
,
rectangle
, or
polygon
), and use the parameters to specify shape’s position, size, and other information
like the number of sides in a polygon.
Remember:
All measurements and page coordinates are processed as points by the scripting engine. For details,
see
Measurement units
” on page 29
.
x and y coordinates are measured from the bottom-left corner of the document, as indicated in the
Info panel in the Illustrator application. For details, see
Page-item positioning and dimensions
” on
page 29
.