Adobe 65014293 Scripting Guide - Page 52

Solid color classes, Using hex values for RGB color, Getting and converting colors

Page 52 highlights

CHAPTER 3: Scripting Photoshop Solid color classes The solid color classes available in Photoshop are illustrated below. Color Classes Solid Color Working with color objects 52 RGB Color CMYK Color Gray Color HSB Color Lab Color No Color Using hex values for RGB color You can express RGB colors as hex (or hexadecimal) values. A hex value contains three pairs of numbers which represent red, blue and green (in that order). In AppleScript, the hex value is represented by the hex value string property in class RGB hex color, and you use the convert color command described below to retrieve the hex value. In VBScript and JavaScript, the RGBColor object has a string property called HexValue/hexValue. Getting and converting colors The following examples convert an RGB color to its CMYK equivalent. AS The following script, which assumes an RGB color model, gets the foreground color and then uses the convert command of the color class to convert the color to its CMYK equivalent. get foreground color convert color foreground color to CMYK Look up the following in the Adobe Photoshop CS4 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary: ➤ In the "Objects" section, the foreground color property of the class application ➤ In the "Commands" section, convert VBS The following script uses an If Then statement and the model property of the SolidColor object to determine the color model in use. The If Then statement returns a SolidColor object; if it returns an RGB object, the cmyk property of the SolidColor object then allows you to access the color with its CMYK equivalent. Dim someColor If (someColor.model = 2) Then someColor.cmyk 'someColor.model = 2 indicates psColorModel --> 2 (psRGBModel) End If

  • 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
52
Solid color classes
The solid color classes available in Photoshop are illustrated below.
Using hex values for RGB color
You can express RGB colors as hex (or
hexadecimal
) values. A hex value contains three pairs of numbers
which represent red, blue and green (in that order).
In AppleScript, the hex value is represented by the
hex
value
string property in class
RGB
hex
color
, and
you use the
convert
color
command described below to retrieve the hex value.
In VBScript and JavaScript, the
RGBColor
object has a string property called
HexValue/hexValue
.
Getting and converting colors
The following examples convert an RGB color to its CMYK equivalent.
AS
The following script, which assumes an RGB color model, gets the foreground color and then uses the
convert
command of the
color
class to convert the color to its CMYK equivalent.
get foreground color
convert color foreground color to CMYK
Look up the following in the
Adobe Photoshop CS4 AppleScript Scripting Reference
or in the Photoshop
AppleScript Dictionary:
In the “Objects” section, the
foreground color
property of the class
application
In the “Commands” section,
convert
VBS
The following script uses an
If
Then
statement and the
model
property of the
SolidColor
object to
determine the color model in use. The
If
Then
statement returns a
SolidColor
object; if it returns an
RGB
object, the
cmyk
property of the
SolidColor
object then allows you to access the color with its CMYK
equivalent.
Dim someColor
If (someColor.model = 2) Then
someColor.cmyk
'someColor.model = 2 indicates psColorModel --> 2 (psRGBModel)
End If
RGB
Color
CMYK
Color
Gray
Color
HSB
Color
Lab
Color
No
Color
Solid
Color
Color Classes