Skip to content

Commit 4fc2cb5

Browse files
committed
fix: get document by document name from documents.
1 parent 4284f96 commit 4fc2cb5

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

examples/export_layers_use_export_options_saveforweb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Import local modules
99
from photoshop import Session
1010

11+
1112
PSD_FILE = psd.get_psd_files()
1213

1314

examples/get_document_by_name.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Get document by document name from documents."""
2+
3+
# Import third-party modules
4+
import examples._psd_files as psd # Import from examples.
5+
6+
# Import local modules
7+
from photoshop import Session
8+
9+
10+
PSD_FILE = psd.get_psd_files()
11+
slate_template = PSD_FILE["slate_template.psd"]
12+
with Session(slate_template, action="open", auto_close=True) as ps:
13+
for doc in ps.app.documents:
14+
print(doc.name)
15+
print(ps.app.documents.getByName("slate_template.psd").fullName)

photoshop/api/_documents.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,9 @@ def __getitem__(self, item) -> Document:
7676
def length(self) -> int:
7777
return len(list(self.app))
7878

79-
def getByName(self, document_name: str):
80-
return Document(self.app.getByName(document_name))
79+
def getByName(self, document_name: str) -> Document:
80+
"""Get document by given document name."""
81+
for doc in self.app:
82+
if doc.name == document_name:
83+
return Document(doc)
84+
raise PhotoshopPythonAPIError(f'Could not find a document named "{document_name}"')

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ build-backend = "poetry.core.masonry.api"
7272

7373
[tool.black]
7474
line-length = 120
75-
target_version = ['py36']
75+
target_version = ['py37']
7676
include = '\.pyi?$'
7777
exclude = '''
7878

0 commit comments

Comments
 (0)