Skip to content

Commit cb8d380

Browse files
committed
feat: add a new option for create batch
Signed-off-by: longhao <hal.long@outlook.com>
1 parent 1710d61 commit cb8d380

File tree

6 files changed

+142
-4
lines changed

6 files changed

+142
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ result/
2020
# Coverage output
2121
.coverage
2222
/venv/
23+
venv_python
2324

2425
# Docs
2526
docs_src/_build/

examples/run_batch.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Import built-in modules
2+
import os
3+
4+
# Import local modules
5+
from photoshop import Session
6+
7+
8+
root = "your/images/root"
9+
files = []
10+
for name in os.listdir(root):
11+
files.append(os.path.join(root, name))
12+
with Session() as api:
13+
options = api.BatchOptions()
14+
options.destination = 3
15+
options.destinationFolder = "c:\\test"
16+
api.app.batch(files=files, actionName="Quadrant Colors", actionSet="Default Actions", options=options)

photoshop/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Python API for Photoshop."""
2-
32
# Import local modules
43
from photoshop.api import constants
54
from photoshop.api.action_descriptor import ActionDescriptor
65
from photoshop.api.action_list import ActionList
76
from photoshop.api.action_reference import ActionReference
87
from photoshop.api.application import Application
8+
from photoshop.api.batch_options import BatchOptions
99
from photoshop.api.colors import CMYKColor
1010
from photoshop.api.colors import GrayColor
1111
from photoshop.api.colors import HSBColor
@@ -35,6 +35,7 @@
3535
"ActionReference",
3636
"ActionList",
3737
"Application",
38+
"BatchOptions",
3839
"constants",
3940
"enumerations",
4041
"PhotoshopPythonAPIError",

photoshop/api/application.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
app.documents.add(800, 600, 72, "docRef")
1111
1212
"""
13-
1413
# Import built-in modules
1514
import os
1615
from pathlib import Path
@@ -259,13 +258,13 @@ def windowsFileTypes(self):
259258
return self.app.windowsFileTypes
260259

261260
# Methods.
262-
def batch(self, *args, **kwargs):
261+
def batch(self, files, actionName, actionSet, options):
263262
"""Runs the batch automation routine.
264263
265264
Similar to the **File** > **Automate** > **Batch** command.
266265
267266
"""
268-
self.app.bath(*args, **kwargs)
267+
self.app.batch(files, actionName, actionSet, options)
269268

270269
def beep(self):
271270
"""Causes a "beep" sound."""

photoshop/api/batch_options.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# https://theiviaxx.github.io/photoshop-docs/Photoshop/BatchOptions.html
2+
# Import local modules
3+
from photoshop.api._core import Photoshop
4+
5+
6+
class BatchOptions(Photoshop):
7+
object_name = "BatchOptions"
8+
9+
def __init__(self):
10+
super().__init__()
11+
12+
@property
13+
def destination(self):
14+
"""The type of destination for the processed files."""
15+
return self.app.destination
16+
17+
@destination.setter
18+
def destination(self, value):
19+
self.app.destination = value
20+
21+
@property
22+
def destinationFolder(self):
23+
"""The folder location for the processed files. Valid only when ‘destination’ = folder."""
24+
return self.app.destinationFolder
25+
26+
@destinationFolder.setter
27+
def destinationFolder(self, path):
28+
self.app.destinationFolder = path
29+
30+
@property
31+
def errorFile(self):
32+
"""The file in which to log errors encountered.
33+
To display errors on the screen and stop batch processing when errors occur, leave blank."""
34+
return self.app.errorFile
35+
36+
@errorFile.setter
37+
def errorFile(self, file_path):
38+
self.app.errorFile = file_path
39+
40+
@property
41+
def fileNaming(self) -> list:
42+
"""A list of file naming options. Maximum: 6."""
43+
return self.app.fileNaming
44+
45+
@fileNaming.setter
46+
def fileNaming(self, file_naming: list):
47+
self.app.fileNaming = file_naming
48+
49+
@property
50+
def macintoshCompatible(self) -> bool:
51+
"""If true, the final file names are Macintosh compatible."""
52+
return self.app.macintoshCompatible
53+
54+
@macintoshCompatible.setter
55+
def macintoshCompatible(self, value: bool):
56+
self.app.macintoshCompatible = value
57+
58+
@property
59+
def overrideOpen(self) -> bool:
60+
"""If true, overrides action open commands."""
61+
return self.app.overrideOpen
62+
63+
@overrideOpen.setter
64+
def overrideOpen(self, value: bool):
65+
self.app.overrideOpen = value
66+
67+
@property
68+
def overrideSave(self) -> bool:
69+
"""If true, overrides save as action steps with the specified destination."""
70+
return self.app.overrideSave
71+
72+
@overrideSave.setter
73+
def overrideSave(self, value: bool):
74+
self.app.overrideSave = value
75+
76+
@property
77+
def startingSerial(self) -> int:
78+
"""The starting serial number to use in naming files."""
79+
return self.app.startingSerial
80+
81+
@startingSerial.setter
82+
def startingSerial(self, value: int):
83+
self.app.startingSerial = value
84+
85+
@property
86+
def suppressOpen(self) -> bool:
87+
"""If true, suppresses file open options dialogs."""
88+
return self.app.suppressOpen
89+
90+
@suppressOpen.setter
91+
def suppressOpen(self, value: bool):
92+
self.app.suppressOpen = value
93+
94+
@property
95+
def suppressProfile(self) -> bool:
96+
"""If true, suppresses color profile warnings."""
97+
return self.app.suppressProfile
98+
99+
@suppressProfile.setter
100+
def suppressProfile(self, value: bool):
101+
self.app.suppressProfile = value
102+
103+
@property
104+
def unixCompatible(self) -> bool:
105+
"""If true, the final file names are Unix compatible."""
106+
return self.app.unixCompatible
107+
108+
@unixCompatible.setter
109+
def unixCompatible(self, value: bool):
110+
self.app.unixCompatible = value
111+
112+
@property
113+
def windowsCompatible(self) -> bool:
114+
"""If true, the final file names are Windows compatible."""
115+
return self.app.windowsCompatible
116+
117+
@windowsCompatible.setter
118+
def windowsCompatible(self, value: bool):
119+
self.app.windowsCompatible = value

photoshop/session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from photoshop.api import ActionReference
3636
from photoshop.api import Application
3737
from photoshop.api import BMPSaveOptions
38+
from photoshop.api import BatchOptions
3839
from photoshop.api import CMYKColor
3940
from photoshop.api import EPSSaveOptions
4041
from photoshop.api import EventID
@@ -128,6 +129,7 @@ def __init__(
128129
self.EventID = EventID
129130
self.SolidColor = SolidColor
130131
self.TextItem = TextItem
132+
self.BatchOptions = BatchOptions
131133

132134
# The save options.
133135
self.GIFSaveOptions = GIFSaveOptions

0 commit comments

Comments
 (0)