Document¶
src.helpers.document.get_leaf_layers(group: Optional[LayerSet] = None) -> list[ArtLayer]
¶
Utility function to generate a list of leaf layers in a LayerSet or document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
LayerSet | None
|
Group to grab leaf layers from. |
None
|
Returns:
| Type | Description |
|---|---|
list[ArtLayer]
|
A list of leaf layers in a LayerSet or document. |
Source code in src\helpers\document.py
src.helpers.document.get_layer_tree(group: Optional[LayerSet] = None) -> dict[str, Union[ArtLayer, dict[str, ArtLayer]]]
¶
Composes a dictionary tree of layers in the active document or a specific LayerSet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
LayerSet | None
|
A specific group to create a dictionary tree for. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ArtLayer | dict[str, ArtLayer]]
|
A dictionary tree comprised of all the layers in a document or group. |
Source code in src\helpers\document.py
src.helpers.document.import_art(layer: ArtLayer, path: Union[str, Path], name: str = 'Layer 1', docref: Optional[Document] = None) -> ArtLayer
¶
Imports an art file into the active layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
Layer to make active and receive image. |
required |
path
|
str | Path
|
Image file to import. |
required |
name
|
str
|
Name of the new layer. |
'Layer 1'
|
docref
|
Document | None
|
Reference document if provided, otherwise use active. |
None
|
Returns:
| Type | Description |
|---|---|
ArtLayer
|
Imported art layer. |
Source code in src\helpers\document.py
src.helpers.document.import_svg(path: Union[str, Path], ref: Union[ArtLayer, LayerSet] = None, placement: Optional[ElementPlacement] = None, docref: Optional[Document] = None) -> ArtLayer
¶
Imports an SVG image, then moves it if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
SVG file to import. |
required |
ref
|
ArtLayer | LayerSet
|
Reference used to move layer. |
None
|
placement
|
ElementPlacement | None
|
Placement based on the reference. |
None
|
docref
|
Document | None
|
Reference document if provided, otherwise use active. |
None
|
Returns:
| Type | Description |
|---|---|
ArtLayer
|
Imported SVG layer. |
Source code in src\helpers\document.py
src.helpers.document.paste_file(layer: ArtLayer, path: Union[str, Path], action: any = None, action_args: dict = None, docref: Optional[Document] = None) -> ArtLayer
¶
Pastes the given file into the specified layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer
|
Layer object to paste the image into. |
required |
path
|
str | Path
|
Filepath of the image to open. |
required |
action
|
any
|
Optional action function to call on the image before importing it. |
None
|
action_args
|
dict
|
Optional arguments to pass to the action function. |
None
|
docref
|
Document | None
|
Reference document if provided, otherwise use active. |
None
|
Returns:
| Type | Description |
|---|---|
ArtLayer
|
Active layer where art was pasted. |
Source code in src\helpers\document.py
src.helpers.document.import_art_into_new_layer(path: Union[str, Path], name: str = 'New Layer', docref: Optional[Document] = None) -> ArtLayer
¶
Creates a new layer and imports a given art into that layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Image file to import, must have a valid image extension. |
required |
name
|
str
|
Chosen name of the new layer. |
'New Layer'
|
docref
|
Document | None
|
Reference document if provided, otherwise use active. |
None
|
Returns:
| Type | Description |
|---|---|
ArtLayer
|
New ArtLayer with imported art. |
Source code in src\helpers\document.py
src.helpers.document.jump_to_history_state(position: int)
¶
Jump to a position in the history state relative to its current position. 2 moves forward two, -2 moves backwards two.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
int
|
Integer value determining how far ahead or behind in the state to move. |
required |
Source code in src\helpers\document.py
src.helpers.document.toggle_history_state(direction: str = 'previous') -> None
¶
Alter the history state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
str
|
Direction to move the history state ("previous" or "next"). |
'previous'
|
Source code in src\helpers\document.py
src.helpers.document.undo_action() -> None
¶
src.helpers.document.redo_action() -> None
¶
src.helpers.document.reset_document(docref: Optional[Document] = None) -> None
¶
Reset to the history state to when document was first opened.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docref
|
Document | None
|
Reference document to reset state in, use active if not provided. |
None
|
Source code in src\helpers\document.py
src.helpers.document.points_to_pixels(number: Union[int, float], docref: Optional[Document] = None) -> float
¶
Converts a given number in point units to pixel units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int | float
|
Number represented in point units. |
required |
docref
|
Document | None
|
Document to reference, use active if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Float representing the given value in pixel units. |
Source code in src\helpers\document.py
src.helpers.document.pixels_to_points(number: Union[int, float], docref: Optional[Document] = None) -> float
¶
Converts a given number in pixel units to point units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int | float
|
Number represented in pixel units. |
required |
docref
|
Document | None
|
Document to reference, use active if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Float representing the given value in point units. |
Source code in src\helpers\document.py
src.helpers.document.check_active_document() -> bool
¶
Checks if there are any active documents loaded in Photoshop.
Returns:
| Type | Description |
|---|---|
bool
|
True if exists, otherwise False. |
Source code in src\helpers\document.py
src.helpers.document.get_document(name: str) -> Optional[Document]
¶
Check if a Photoshop Document has been loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Filename of the document. |
required |
Returns:
| Type | Description |
|---|---|
Document | None
|
The Document if located, None if missing. |
Source code in src\helpers\document.py
src.helpers.document.trim_transparent_pixels() -> None
¶
Trim transparent pixels from Photoshop document.
Source code in src\helpers\document.py
src.helpers.document.save_document_png(path: Path, docref: Optional[Document] = None) -> None
¶
Save the current document as a PNG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to save the PNG file. |
required |
docref
|
Document | None
|
Current active document. Use active if not provided. |
None
|
Source code in src\helpers\document.py
src.helpers.document.save_document_jpeg(path: Path, optimize: bool = True, docref: Optional[Document] = None) -> None
¶
Save the current document as a JPEG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to save the JPEG file. |
required |
optimize
|
bool
|
Whether to save with "Optimize Baseline". Reduces file size, but may cause an error on older versions of Photoshop. |
True
|
docref
|
Document | None
|
Current active document. Use active if not provided. |
None
|
Source code in src\helpers\document.py
src.helpers.document.save_document_psd(path: Path, docref: Optional[Document] = None) -> None
¶
Save the current document as a PSD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to save the PSD file. |
required |
docref
|
Document | None
|
Open Photoshop document. Use active if not provided. |
None
|
Source code in src\helpers\document.py
src.helpers.document.save_document_psb(path: Path, *_args, **_kwargs) -> None
¶
Save the current document as a PSB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to save the PSB file. |
required |
_args
|
Ignored args used by similar methods but not here. |
()
|
|
_kwargs
|
Ignored kwargs used by similar methods but not here. |
{}
|
Source code in src\helpers\document.py
src.helpers.document.close_document(save: bool = False, docref: Optional[Document] = None, purge: bool = True) -> None
¶
Close the active document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save
|
bool
|
Whether to save changes to the document before closing. |
False
|
docref
|
Document | None
|
Open Photoshop document. Use active if not provided. |
None
|
purge
|
bool
|
Whether to purge all caches. |
True
|
Source code in src\helpers\document.py
src.helpers.document.rotate_document(angle: int) -> None
¶
Rotate the document.
Returns:
| Name | Type | Description |
|---|---|---|
angle |
None
|
Angle to rotate the document. |
Source code in src\helpers\document.py
src.helpers.document.rotate_counter_clockwise() -> None
¶
src.helpers.document.rotate_clockwise() -> None
¶
src.helpers.document.rotate_full() -> None
¶
src.helpers.document.paste_to_document(layer: Union[ArtLayer, LayerSet, None] = None)
¶
Paste current clipboard to the current layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ArtLayer | LayerSet | None
|
Layer to make active, if provided. |
None
|