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.open(path, appendToRecent=True)¶
Open a document. When the document is already opened it is returned instead.
- Parameters:
- Returns:
The newly opened or already open document
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter path is empty
CometError – When document could not be opened
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- 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()¶
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:
- 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()¶
Fetch a list of all currently open documents
- Returns:
List of opened documents.
- Return type:
- 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