comet.CBook¶
- class comet.CBook¶
CBook represents an opened InDesign® book.
See also
- Module
book
Book access and queries
Methods¶
- CBook.isValid() bool ¶
Determine whether the book is valid and open
- Returns:
Whether the book is valid and open
- Return type:
- Available:
InDesign®
- CScript:
- CBook.getPath() str ¶
Determine the full path to the book
- Returns:
The full path to the book
- Return type:
- Raises:
On internal error
When the book is not open
- Available:
InDesign®
- CScript:
- CBook.getDocuments() list[str] ¶
Get a list of the full path to each document in the book
- Returns:
List of full pathes to each document in the book
- Return type:
- Raises:
On internal error
When the book is not open
- Available:
InDesign®
- CScript:
- CBook.save() None ¶
Save the book.
- Return type:
None
- Raises:
TypeError – When parameter types are invalid
On internal error
When the book is not open
- Available:
InDesign®
- CScript:
- CBook.close(save: bool = True) None ¶
Close the book.
- CBook.setCurrent() None ¶
Set the book as the current one
- Return type:
None
- Raises:
On internal error
When the book is not open
- Available:
InDesign®
- See also:
- CScript:
- CBook.insertDocument(document: str | CDocument, index: int = -1, repaginate: bool = True, updateCrossRefs: bool = False) None ¶
Insert a document into a book. The book must be open. If the document is already in the book, the call is ignored.
- Parameters:
- Return type:
None
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter document is of type
str
and is emptyFileNotFoundError – When parameter document is of type
str
and points to a file that does not existOn internal error
When the book is not open
- Available:
InDesign®
- CScript:
- CBook.removeDocument(document: str | int | CDocument, repaginate: bool = True, updateCrossRefs: bool = False) None ¶
Remove a document from the book.
If the document is not in the book, the call is ignored.
- Parameters:
- Return type:
None
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter document is of type
str
and is emptyIndexError – When parameter document is of type
int
and is out of boundsOn internal error
When the book is not open
- Available:
InDesign®
- CScript:
- CBook.getDocumentPosition(document: str | CDocument) int ¶
Find the index of a document in the book
- Parameters:
The document to find.
The parameter type can be:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter document is of type
str
and is emptyKeyError – When the document is not in the book
On internal error
When the book is not open
- Returns:
The index of the document in the book
- Return type:
- Available:
InDesign®
- CScript:
- CBook.setDocumentPosition(document: str | int | CDocument, index: int, repaginate: bool = True, updateCrossRefs: bool = False) None ¶
Move a document inside the book to a new index
- Parameters:
- Return type:
None
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter document is of type
str
and is emptyIndexError – When parameter document is of type
int
and is out of boundsKeyError – When parameter document is of type
str
orCDocument
and is not part of the bookOn internal error
When the book is not open
- Available:
InDesign®
- CScript:
- CBook.getDocumentPageRange(document: str | int | CDocument) tuple[int, int] ¶
Determine the page range of a document of the book.
The result page range is 0-based
- Parameters:
document (str | int | CDocument) –
The document to determine the page range for.
The parameter type can be:
- Returns:
The page range of the document as [start, end].
The values are 0-based.
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter document is of type
str
and is emptyIndexError – When parameter document is of type
int
and is out of boundsKeyError – When parameter document is of type
str
orCDocument
and is not part of the bookOn internal error
When the book is not open
- Available:
InDesign®
- CBook.getMasterDocument() str ¶
Get the master document of the book
- Returns:
Full path to the book’s master document
- Return type:
- Raises:
On internal error
When the book is not open
- Available:
InDesign®
- CScript:
- CBook.setMasterDocument(document: str | int | CDocument) None ¶
Set the master document of the book
- Parameters:
document –
The new master document
The parameter type can be:
- Return type:
None
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter document is of type
str
and is emptyIndexError – When parameter document is of type
int
and is out of boundsKeyError – When parameter document is of type
str
orCDocument
and is not part of the book
- Available:
InDesign®
- CScript:
- CBook.repaginate(updateCrossRefs: bool = False) None ¶
Recalculate page numbers in the book
- CBook.exportPDF(exportPath: str = '', styleName: str = '') None ¶
Export the book to a PDF document
- Parameters:
- Return type:
None
- Raises:
TypeError – When parameter types are invalid
On internal error
When the book is not open
- Available:
InDesign®
- CScript:
- CBook.executeForAllDocs(actionID: int, saveOnClose: bool = False) None ¶
Process all documents in this book.
The documents are opened, processed, and closed again in the order specified in the book.
Previously opened documents remain open.
This function solves the problem that InDesign® documents are only actually closed during the next idle time.
This behavior causes books with many documents to quickly lead to memory overflow and InDesign® crashes when edited in a single script.
This function solves this problem by editing each document in its own idle time sequence.
Between these steps, InDesign® has enough time to really close closed documents.
- Parameters:
actionID (int) –
ID of the actions script which is executed for each document.
Each document is open and raised to the front at the time of the execution.
The script is executed in the kContextProcessBookDocument environment.
saveOnClose (bool) –
Should individual documents be saved after editing?
- Return type:
None
- Raises:
TypeError – When parameter types are invalid
On internal error
When the book is not open
- Available:
InDesign®
- CScript: