forked from lohriialo/photoshop-scripting-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps.py
83 lines (72 loc) · 3.21 KB
/
ps.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
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
import time
from win32com.client import Dispatch, GetActiveObject, GetObject
# This is a test script written to see how Python scripting works in executing
# Photoshop actions, ExecuteAction()
# Where did I get all this action stuffs(ActionDescriptor, ActionReference, CharIDToTypeID etc)?
# It's generated by a plugin Photoshop provides or you can generate one yourself
# See https://www.adobe.com/devnet/photoshop/scripting.html
# Start up Photoshop application
# app = Dispatch('Photoshop.Application')
# Or get Reference to already running Photoshop application
# app = GetObject(Class="Photoshop.Application")
app = GetActiveObject("Photoshop.Application")
# psDisplayNoDialogs is a PS COM constant, see pscc2018.py or scripting COM
psDisplayNoDialogs = 3
for index, x in enumerate(range(50)):
# app.DoAction('Sepia Toning (layer)', 'Default Actions')
# Execute an existing action from action palette
idPly = app.CharIDToTypeID("Ply ")
desc8 = Dispatch('Photoshop.ActionDescriptor')
idnull = app.CharIDToTypeID("null")
ref3 = Dispatch('Photoshop.ActionReference')
idActn = app.CharIDToTypeID("Actn")
ref3.PutName(idActn, "Sepia Toning (layer)")
idASet = app.CharIDToTypeID("ASet")
ref3.PutName(idASet, "Default Actions")
desc8.PutReference(idnull, ref3)
app.ExecuteAction(idPly, desc8, psDisplayNoDialogs)
# This time delay prevents COM busy error
time.sleep(0.5)
# Create solid color fill layer.
idMk = app.CharIDToTypeID("Mk ")
desc21 = Dispatch('Photoshop.ActionDescriptor')
idNull = app.CharIDToTypeID("null")
ref12 = Dispatch('Photoshop.ActionReference')
idContentLayer1 = app.StringIDToTypeID("contentLayer")
ref12.PutClass(idContentLayer1)
desc21.PutReference(idNull, ref12)
idUsng = app.CharIDToTypeID("Usng")
desc22 = Dispatch('Photoshop.ActionDescriptor')
idType = app.CharIDToTypeID("Type")
desc23 = Dispatch('Photoshop.ActionDescriptor')
idClr = app.CharIDToTypeID("Clr ")
desc24 = Dispatch('Photoshop.ActionDescriptor')
idRd = app.CharIDToTypeID("Rd ")
desc24.PutDouble(idRd, index)
idGrn = app.CharIDToTypeID("Grn ")
desc24.PutDouble(idGrn, index)
idBl = app.CharIDToTypeID("Bl ")
desc24.PutDouble(idBl, index)
idRGBC = app.CharIDToTypeID("RGBC")
desc23.PutObject(idClr, idRGBC, desc24)
idSolidColorLayer = app.StringIDToTypeID("solidColorLayer")
desc22.PutObject(idType, idSolidColorLayer, desc23)
idContentLayer2 = app.StringIDToTypeID("contentLayer")
desc21.PutObject(idUsng, idContentLayer2, desc22)
app.ExecuteAction(idMk, desc21, psDisplayNoDialogs)
time.sleep(0.5)
# Select mask
idSlct = app.CharIDToTypeID("slct")
desc38 = Dispatch('Photoshop.ActionDescriptor')
idNull1 = app.CharIDToTypeID("null")
ref20 = Dispatch('Photoshop.ActionReference')
idChnl1 = app.CharIDToTypeID("Chnl")
idChnl2 = app.CharIDToTypeID("Chnl")
idMsk = app.CharIDToTypeID("Msk ")
ref20.PutEnumerated(idChnl1, idChnl2, idMsk)
desc38.PutReference(idNull1, ref20)
idMkVs = app.CharIDToTypeID("MkVs")
desc38.PutBoolean(idMkVs, False)
app.ExecuteAction(idSlct, desc38, psDisplayNoDialogs)
time.sleep(0.5)
app.ActiveDocument.ActiveLayer.Invert()