comet.document
The comet.document module provides global document access for the current session, e.g. finding open documents or opening new ones.
See also
- Class
CDocument
Document object specific functionality
Methods
-
comet.document.create(options: dict[str, int | float] = {}) → CDocument
Create a new, empty document.
- Parameters:
options (dict[str, int | float]) –
Options to create the document.
Common options
’width’
Type: float
Description: Page width in pt
Default: 595.276pt (DIN A4)
’height’
Type: float
Description: Page width in pt
Default: 841.89pt (DIN A4)
’pages’
Type: int
Description: Number of pages
Default: 1
’pagesPerSpread’
Type: int
Description: Number of pages per spread
Default: 2
’scale’
Type: float
Description: Scaling in the document window. 1.0 is 100%.
Default: 1.0
’left’, ‘top’, ‘right’, ‘bottom’
Type: int
Description: Position and size of the document window in pixels. The values are only applied if all four values are specified and left < right and top < bottom.
Default: 0
’columns’
Type: int
Description: Number of columns on the pages.
Default: 1
’gutter’
Type: float
Description: Column gutter in pt.
Default: 12.0
’direction’
Type: int
Description: Direction of document columns.
0: Horizontal
1: Vertical
2: Roman
3: CJK
Default: 1
’restartPageNums’
Type: int
Description: Restart page numbering? This information is only used when the document is used in books.
Default: -1
’bindingDirection’
Type: int
Description: Page binding
Default: -1
’intent’
Type: int
Description: Target medium
Default: -1
’ml’, ‘mt’, ‘mr’, ‘mb’
Type: float
Description: Page margins in pt
-2.0: Setting the current document if no document is open 36.0.
-1.0: Standard 36.0
> -1.0 and < 0.0: Percentage of the page (0.1 corresponds to 10%)
≥ 0.0: Absolute value in points
Default: -1.0
’startPageIndex’
Type: int
Description: Which page index should the document start with?
Default: 0
- Returns:
The newly created document
- Return type:
CDocument
- Raises:
TypeError – When parameter types are invalid
- CScript:
document::create
- Available:
InDesign® comet_pdf®
-
comet.document.open(path: str, appendToRecent: bool = True) → CDocument
Open a document. When the document is already opened it is returned instead.
- Parameters:
-
- Returns:
The newly opened or already open document
- Return type:
CDocument
- Raises:
-
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
document::open
- Examples:
Open a document without appending it to recent files.
#!py
import comet
def main():
#Open the document from the desktop
comet.document.open(
"$DESKTOP/HelloWorld.indd",
appendToRecent = False
)
return 0
-
comet.document.getFront() → CDocument | None
Return the current front document if any, else returns None
- Returns:
The current front document
- Return type:
CDocument | None
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
document::get_front
- Examples:
Get the front document if any exists and write the name to the logfile.
#!py
import comet
def main():
#Get the front document if any exists
document = comet.document.getFront()
if document:
#There is a front document
comet.wlog(f'The front document is "{document.getName()}"')
else:
#There is no front document
comet.wlog('There is no front document')
return 0
-
comet.document.getOpen() → list[CDocument]
Fetch a list of all currently open documents
- Returns:
List of opened documents.
- Return type:
list[CDocument]
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
-
- Examples:
Get all open documents and log their names and indices to the logfile.
#!py
import comet
def main():
#Get all currently open documents
documents: list[comet.CDocument] = comet.document.getOpen()
#Use zip to create tuples of document, index to iterate over both
for document, index in zip(documents, range(len(documents))):
#Write the document name and index into the logfile
comet.wlog(f'Document {index}: "{document.getName()}"')
return 0