Skip to content

documents

Documents

Bases: Photoshop

The collection of open documents.

Source code in photoshop/api/_documents.py
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
81
82
83
84
85
class Documents(Photoshop):
    """The collection of open documents."""

    def __init__(self, parent):
        super().__init__(parent=parent)
        self._flag_as_method("add")

    def __len__(self) -> int:
        return self.length

    def add(
        self,
        width: int = 960,
        height: int = 540,
        resolution: float = 72.0,
        name: str = None,
        mode: int = NewDocumentMode.NewRGB,
        initialFill: int = DocumentFill.White,
        pixelAspectRatio: float = 1.0,
        bitsPerChannel: int = BitsPerChannelType.Document8Bits,
        colorProfileName: str = None,
    ) -> Document:
        """Creates a new document object and adds it to this collections.

        Args:
            width (int): The width of the document.
            height (int): The height of the document.
            resolution (int): The resolution of the document (in pixels per inch)
            name (str): The name of the document.
            mode (): The document mode.
            initialFill : The initial fill of the document.
            pixelAspectRatio: The initial pixel aspect ratio of the document.
                                Default is `1.0`, the range is `0.1-10.00`.
            bitsPerChannel: The number of bits per channel.
            colorProfileName: The name of color profile for document.

        Returns:
            .Document: Document instance.

        """
        return Document(
            self.app.add(
                width,
                height,
                resolution,
                name,
                mode,
                initialFill,
                pixelAspectRatio,
                bitsPerChannel,
                colorProfileName,
            )
        )

    def __iter__(self) -> Document:
        for doc in self.app:
            self.adobe.activeDocument = doc
            yield Document(doc)

    def __getitem__(self, item) -> Document:
        try:
            return Document(self.app[item])
        except IndexError:
            raise PhotoshopPythonAPIError("Currently Photoshop did not find Documents.")

    @property
    def length(self) -> int:
        return len(list(self.app))

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

add(width=960, height=540, resolution=72.0, name=None, mode=NewDocumentMode.NewRGB, initialFill=DocumentFill.White, pixelAspectRatio=1.0, bitsPerChannel=BitsPerChannelType.Document8Bits, colorProfileName=None)

Creates a new document object and adds it to this collections.

Parameters:

Name Type Description Default
width int

The width of the document.

960
height int

The height of the document.

540
resolution int

The resolution of the document (in pixels per inch)

72.0
name str

The name of the document.

None
mode

The document mode.

NewRGB
initialFill

The initial fill of the document.

White
pixelAspectRatio float

The initial pixel aspect ratio of the document. Default is 1.0, the range is 0.1-10.00.

1.0
bitsPerChannel int

The number of bits per channel.

Document8Bits
colorProfileName str

The name of color profile for document.

None

Returns:

Type Description
Document

.Document: Document instance.

Source code in photoshop/api/_documents.py
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
def add(
    self,
    width: int = 960,
    height: int = 540,
    resolution: float = 72.0,
    name: str = None,
    mode: int = NewDocumentMode.NewRGB,
    initialFill: int = DocumentFill.White,
    pixelAspectRatio: float = 1.0,
    bitsPerChannel: int = BitsPerChannelType.Document8Bits,
    colorProfileName: str = None,
) -> Document:
    """Creates a new document object and adds it to this collections.

    Args:
        width (int): The width of the document.
        height (int): The height of the document.
        resolution (int): The resolution of the document (in pixels per inch)
        name (str): The name of the document.
        mode (): The document mode.
        initialFill : The initial fill of the document.
        pixelAspectRatio: The initial pixel aspect ratio of the document.
                            Default is `1.0`, the range is `0.1-10.00`.
        bitsPerChannel: The number of bits per channel.
        colorProfileName: The name of color profile for document.

    Returns:
        .Document: Document instance.

    """
    return Document(
        self.app.add(
            width,
            height,
            resolution,
            name,
            mode,
            initialFill,
            pixelAspectRatio,
            bitsPerChannel,
            colorProfileName,
        )
    )

getByName(document_name)

Get document by given document name.

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

Last update: 2024-11-17
Created: 2024-11-17