forked from lohriialo/photoshop-scripting-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActiveLayer.py
More file actions
25 lines (20 loc) · 841 Bytes
/
ActiveLayer.py
File metadata and controls
25 lines (20 loc) · 841 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
# Set the active layer to the last art layer of the active document, or the
# first if the last is already active.
from win32com.client import Dispatch, GetActiveObject, GetObject
# Start up Photoshop application
# app = Dispatch('Photoshop.Application')
# Or get Reference to already running Photoshop application instance
# app = GetObject(Class="Photoshop.Application")
app = GetActiveObject("Photoshop.Application")
if len(app.Documents) < 1:
docRef = app.Documents.Add()
else:
docRef = app.ActiveDocument
if len(docRef.Layers) < 2:
docRef.ArtLayers.Add()
activeLayerName = docRef.ActiveLayer.Name
SetLayerName = ''
if docRef.ActiveLayer.Name != app.ActiveDocument.Layers.Item(len(docRef.Layers)).Name:
docRef.ActiveLayer = docRef.Layers.Item(len(docRef.Layers))
else:
docRef.ActiveLayer = docRef.Layers.Item(1)