Adobe 65015634 Scripting Guide - Page 70

Adobe Photoshop CS4 JavaScript Scripting Reference, Look up the following classes in

Page 70 highlights

CHAPTER 3: Scripting Photoshop Advanced Scripting 70 JS To select an area and apply a wave filter to it: 1. Type the following code into the script file HelloWorldDoc just above the statements that restore original preferences: //create new variables to contain doc width and height //convert inches to pixels by multiplying the number of inches by //the resolution (which equals number of pixels per inch) docWidthInPixels = docWidthInInches * resolution docHeightInPixels = docHeightInInches * resolution //use the rasterize method of the artLayer class newTextLayer.rasterize(RasterizeType.TEXTCONTENTS) //create a variable to contain the coordinate values //for the selection object selRegion = Array(Array(0, 0), Array(docWidthInPixels / 2, 0), Array(docWidthInPixels / 2, docHeightInPixels), Array(0, docHeightInPixels), Array(0, 0)) //use the select method of the selection object //to create an object and give it the selRegion values //as coordinates docRef.selection.select(selRegion) newTextLayer.applyWave(1, 1, 100, 5, 10, 100, 100, WaveType.SINE, UndefinedAreas.WRAPAROUND, 0) 2. Save the script, and then open Photoshop and select the script from the Scripts menu (choose File > Script > HelloWorldDoc). 3. After viewing the document in Photoshop, close Photoshop without saving the document. NOTE: Look up the following classes in the Adobe Photoshop CS4 JavaScript Scripting Reference, or in the ExtendScript Object Model Viewer to see if you understand how you used them in this script: ➤ ArtLayer ➣ rasterize() method. Notice that the RasterizeType.TEXTCONTENTS argument uses the RasterizeType constant. Constants are always depicted in upper case letters in Photoshop JavaScripts. ➣ applyWave() method

  • 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
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

C
HAPTER
3: Scripting Photoshop
Advanced Scripting
70
JS
To select an area and apply a wave filter to it:
1.
Type the following code into the script file
HelloWorldDoc
just above the statements that restore
original preferences:
//create new variables to contain doc width and height
//convert inches to pixels by multiplying the number of inches by
//the resolution (which equals number of pixels per inch)
docWidthInPixels = docWidthInInches * resolution
docHeightInPixels = docHeightInInches * resolution
//use the rasterize method of the artLayer class
newTextLayer.rasterize(RasterizeType.TEXTCONTENTS)
//create a variable to contain the coordinate values
//for the selection object
selRegion = Array(Array(0, 0),
Array(docWidthInPixels / 2, 0),
Array(docWidthInPixels / 2, docHeightInPixels),
Array(0, docHeightInPixels),
Array(0, 0))
//use the select method of the selection object
//to create an object and give it the selRegion values
//as coordinates
docRef.selection.select(selRegion)
newTextLayer.applyWave(1, 1, 100, 5, 10, 100, 100,
WaveType.SINE, UndefinedAreas.WRAPAROUND, 0)
2.
Save the script, and then open Photoshop and select the script from the Scripts menu (choose
File >
Script > HelloWorldDoc
).
3.
After viewing the document in Photoshop, close Photoshop without saving the document.
N
OTE
:
Look up the following classes in the
Adobe Photoshop CS4 JavaScript Scripting Reference
, or in the
ExtendScript Object Model Viewer to see if you understand how you used them in this script:
ArtLayer
rasterize()
method. Notice that the
RasterizeType.TEXTCONTENTS
argument uses the
RasterizeType
constant. Constants are always depicted in upper case letters in Photoshop
JavaScripts.
applyWave()
method