-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathHelloWorld.py
More file actions
38 lines (29 loc) · 1.15 KB
/
Copy pathHelloWorld.py
File metadata and controls
38 lines (29 loc) · 1.15 KB
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
"""
Photoshop scripting sample (Python / Windows COM).
"""
import sys
from pathlib import Path
_ROOT = Path(__file__).resolve().parents[2]
if str(_ROOT) not in sys.path:
sys.path.insert(0, str(_ROOT))
from photoshop_scripting import require_windows_com
require_windows_com() # these samples use the Windows COM object model
from photoshop_scripting import get_app
# --- Application ---
# Connect to Photoshop (launches or attaches to a running instance).
app = get_app()
# --- Document ---
# Documents.Add(width, height, resolution=..., name=...) creates a new doc.
# Units follow Preferences.RulerUnits (default is often pixels).
doc_ref = app.Documents.Add(320, 240)
# --- Layer ---
# ArtLayers.Add() creates a normal raster layer on top of the stack.
layer_ref = doc_ref.ArtLayers.Add()
# PsLayerKind: 1=normal, 2=text, … Convert this layer into a text layer.
ps_text_layer = 2 # PsLayerKind.psTextLayer
layer_ref.Kind = ps_text_layer
# --- TextItem ---
# Text layers expose .TextItem for contents, font metrics, and position.
text_item = layer_ref.TextItem
text_item.Contents = "HELLO WORLD!"
text_item.Position = (120, 120) # (x, y) in current ruler units