-
Notifications
You must be signed in to change notification settings - Fork 92
/
WorkingWithText.py
43 lines (35 loc) · 1.43 KB
/
WorkingWithText.py
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
# Create a new art layer and convert it to a text layer.
# Set its contents, size and color.
# from win32com.client import Dispatch, GetActiveObject
from comtypes.client import GetActiveObject, CreateObject
# Start up Photoshop application
# Or get Reference to already running Photoshop application instance
# app = Dispatch('Photoshop.Application')
app = GetActiveObject("Photoshop.Application")
strtRulerUnits = app.Preferences.RulerUnits
strtTypeUnits = app.Preferences.TypeUnits
psInches = 2 # from enum PsUnits
psTypePoints = 5 # from enum PsTypeUnits
app.Preferences.RulerUnits = psInches
app.Preferences.TypeUnits = psTypePoints
# suppress all dialogs
psDisplayNoDialogs = 3 # from enum PsDialogModes
app.displayDialogs = psDisplayNoDialogs
# create a new document
docRef = app.Documents.Add(7, 5, 72)
# create text color properties
textColor = CreateObject("Photoshop.SolidColor")
textColor.RGB.Red = 225
textColor.RGB.Green = 0
textColor.RGB.Blue = 0
# add a new text layer to document and apply the text color
newTextLayer = docRef.ArtLayers.Add()
psTextLayer = 2 # from enum PsLayerKind
newTextLayer.Kind = psTextLayer
newTextLayer.TextItem.Contents = "Hello, World!"
newTextLayer.TextItem.Position = [0.75, 0.75]
newTextLayer.TextItem.Size = 36
newTextLayer.TextItem.Color = textColor
# set the app preference the way it was before the operation
app.Preferences.RulerUnits = strtRulerUnits
app.Preferences.TypeUnits = strtTypeUnits