Report abuse

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
58
59
60
61
62
63
var extend = function (obj1, obj2) {
  for (key in obj2) { obj1[key] = obj2[key] }
  return obj1
}

// Save the current preferences
var prefs = app.preferences
var startRulerUnits = prefs.rulerUnits
var startTypeUnits = prefs.typeUnits
var startDisplayDialogs = app.displayDialogs

// Set Adobe Photoshop CS5 to use pixels and display no dialogs
prefs.rulerUnits = Units.PIXELS
prefs.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO

// first close all the open documents
while (app.documents.length) {
  app.activeDocument.close()
}

// create a document to work with
var docRef = app.documents.add(5000, 7000, 72, "Simple Line")

var subpath = function (vertex_list) {
  return extend(new SubPathInfo(), {
    operation: ShapeOperation.SHAPEXOR,
    closed: false,
    entireSubPath: vertex_list
  })
}
var vertex = function (anchor, leftDirection, rightDirection) {
  return extend(new PathPointInfo(), {
    kind: PointKind.CORNERPOINT,
    anchor: anchor,
    leftDirection: leftDirection,
    rightDirection: rightDirection
  })
}
var corner_vertex = function (anchor) {
  return vertex(anchor, anchor, anchor)
}
var straight_line = function (start_anchor, end_anchor) {
  return subpath([corner_vertex(start_anchor), corner_vertex(end_anchor)])
}

// create the path item
var myPathItem = docRef.pathItems.add(
  "A Line",
  [ straight_line([100, 100], [150, 200]), // line 1
    straight_line([150, 200], [200, 100]), // line 2
    subpath([
      corner_vertex([200, 100]),                // ice cream curve:
      vertex([150, 50], [100, 50], [200, 50]),  // bezier curve with 3 points
      corner_vertex([100, 100]) ]]))

// stroke the path
myPathItem.strokePath(ToolType.BRUSH)

// Reset the application preferences
prefs.rulerUnits = startRulerUnits
prefs.typeUnits = startTypeUnits
app.displayDialogs = startDisplayDialogs