-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathRotateLayer.py
More file actions
33 lines (26 loc) · 986 Bytes
/
Copy pathRotateLayer.py
File metadata and controls
33 lines (26 loc) · 986 Bytes
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
"""
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
# ArtLayer.Rotate(angle) — rotates the active non-background layer.
app = get_app()
if app.Documents.Count < 1:
print("You must have at least one open document to run this script!")
elif app.ActiveDocument.ActiveLayer.IsBackgroundLayer:
print("Operation cannot be performed on background layer")
else:
doc_ref = app.ActiveDocument
# Layers[0] may work with some COM bridges; Item(1) is the portable form
try:
layer_ref = doc_ref.Layers[0]
except Exception:
layer_ref = doc_ref.Layers.Item(1)
layer_ref.Rotate(45.0)
print("Rotated layer 45°:", layer_ref.Name)