Adobe 65015634 Scripting Guide - Page 51

Working with color objects

Page 51 highlights

CHAPTER 3: Scripting Photoshop Working with color objects 51 // Next create a SubPathInfo object, which holds the line array // in its entireSubPath property. var lineSubPathArray = new Array() lineSubPathArray[0] = new SubPathInfo() lineSubPathArray[0].operation = ShapeOperation.SHAPEXOR lineSubPathArray[0].closed = false lineSubPathArray[0].entireSubPath = lineArray //create the path item, using add. This method takes the SubPathInfo object //and returns a PathItem object, which is added to the pathItems collection // for the document. var myPathItem = docRef.pathItems.add("A Line", lineSubPathArray); // stroke it so we can see something myPathItem.strokePath(ToolType.BRUSH) Working with color objects Your scripts can use the same range of colors that are available from the Photoshop user interface. Each color model has its own set of properties. For example, the RGB color (RGBColor/RGBColor) class contains three properties: red, blue and green. To set a color in this class, you indicate values for each of the three properties. In VBScript and JavaScript, the SolidColor class contains a property for each color model. To use this object, you first create an instance of a SolidColor object, then set appropriate color model properties for the object. Once a color model has been assigned to a SolidColor object, the SolidColor object cannot be reassigned to a different color model. The following examples demonstrate how to set a color using the CMYK color class. AS VBS set foreground color to {class:CMYK color, cyan:20.0,¬ magenta:90.0, yellow:50.0, black:50.0} 'create a solidColor array Dim solidColorRef Set solidColorRef = CreateObject("Photoshop.SolidColor") solidColorRef.CMYK.Cyan = 20 solidColorRef.CMYK.Magenta = 90 solidColorRef.CMYK.Yellow = 50 solidColorRef.CMYK.Black = 50 appRef.ForegroundColor = solidColorRef JS //create a solid color array var solidColorRef = new solidColor() solidColorRef.cmyk.cyan = 20 solidColorRef.cmyk.magenta = 90 solidColorRef.cmyk.yellow = 50 solidColorRef.cmyk.black = 50 foregroundColor = solidColorRef

  • 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
Working with color objects
51
// Next create a SubPathInfo object, which holds the line array
// in its entireSubPath property.
var lineSubPathArray = new Array()
lineSubPathArray[0] = new SubPathInfo()
lineSubPathArray[0].operation = ShapeOperation.SHAPEXOR
lineSubPathArray[0].closed = false
lineSubPathArray[0].entireSubPath = lineArray
//create the path item, using add. This method takes the SubPathInfo object
//and returns a PathItem object, which is added to the pathItems collection
// for the document.
var myPathItem = docRef.pathItems.add("A Line", lineSubPathArray);
// stroke it so we can see something
myPathItem.strokePath(ToolType.BRUSH)
Working with color objects
Your scripts can use the same range of colors that are available from the Photoshop user interface. Each
color model has its own set of properties. For example, the
RGB color
(RGBColor/RGBColor)
class
contains three properties: red, blue and green. To set a color in this class, you indicate values for each of
the three properties.
In VBScript and JavaScript, the
SolidColor
class contains a property for each color model. To use this
object, you first create an instance of a
SolidColor
object, then set appropriate color model properties for
the object. Once a color model has been assigned to a
SolidColor
object, the
SolidColor
object cannot
be reassigned to a different color model.
The following examples demonstrate how to set a color using the
CMYK color
class.
AS
set foreground color to {class:CMYK color, cyan:20.0,¬
magenta:90.0, yellow:50.0, black:50.0}
VBS
'create a solidColor array
Dim solidColorRef
Set solidColorRef = CreateObject("Photoshop.SolidColor")
solidColorRef.CMYK.Cyan = 20
solidColorRef.CMYK.Magenta = 90
solidColorRef.CMYK.Yellow = 50
solidColorRef.CMYK.Black = 50
appRef.ForegroundColor = solidColorRef
JS
//create a solid color array
var solidColorRef = new solidColor()
solidColorRef.cmyk.cyan = 20
solidColorRef.cmyk.magenta = 90
solidColorRef.cmyk.yellow = 50
solidColorRef.cmyk.black = 50
foregroundColor = solidColorRef