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:

bool

Available:

InDesign®

CScript:

book::is_valid

CBook.getPath() str

Determine the full path to the book

Returns:

The full path to the book

Return type:

str

Raises:

CometError

  • On internal error

  • When the book is not open

Available:

InDesign®

CScript:

book::get_path

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:

list[str]

Raises:

CometError

  • 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

  • CometError

    • On internal error

    • When the book is not open

Available:

InDesign®

CScript:

book::save

CBook.close(save: bool = True) None

Close the book.

Parameters:

save (bool) – Save before closing?

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • CometError

    • On internal error

    • When the book is not open

Available:

InDesign®

CScript:

book::close

CBook.setCurrent() None

Set the book as the current one

Return type:

None

Raises:

CometError

  • On internal error

  • When the book is not open

Available:

InDesign®

See also:

book.getCurrent()

CScript:

book::set_current

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:
  • document (str | CDocument) –

    The document to insert

    The parameter type can be:

    • str to incidate the full path to a document

    • CDocument to indicate a document

  • index (int) –

    Index to insert the document at

    • < 0: Insert at end

  • repaginate (bool) – Repaginate?

  • updateCrossRefs (bool) – Update crossref placeholders?

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError – When parameter document is of type str and is empty

  • FileNotFoundError – When parameter document is of type str and points to a file that does not exist

  • CometError

    • On internal error

    • When the book is not open

Available:

InDesign®

CScript:

book::insert

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:
  • document (str | int | CDocument) –

    The document to remove.

    The parameter type can be:

    • str to incidate the full path to a document

    • int to indicate the document index in the book

    • CDocument to indicate a document

  • repaginate (bool) – Repaginate?

  • updateCrossRefs (bool) –

    Update crossref placeholders?

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError – When parameter document is of type str and is empty

  • IndexError – When parameter document is of type int and is out of bounds

  • CometError

    • On internal error

    • When the book is not open

Available:

InDesign®

CScript:

book::remove

CBook.getDocumentPosition(document: str | CDocument) int

Find the index of a document in the book

Parameters:

document (str | CDocument) –

The document to find.

The parameter type can be:

  • str to incidate the full path to a document

  • CDocument to indicate a document

Raises:
  • TypeError – When parameter types are invalid

  • ValueError – When parameter document is of type str and is empty

  • KeyError – When the document is not in the book

  • CometError

    • On internal error

    • When the book is not open

Returns:

The index of the document in the book

Return type:

int

Available:

InDesign®

CScript:

book::position

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:
  • document (str | int | CDocument) –

    The document to move.

    The parameter type can be:

    • str to incidate the full path to a document

    • int to indicate the document index in the book

    • CDocument to indicate a document

  • index (int) – Index to move the document to

  • repaginate (bool) – Repaginate?

  • updateCrossRefs (bool) –

    Update crossref placeholders?

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError – When parameter document is of type str and is empty

  • IndexError – When parameter document is of type int and is out of bounds

  • KeyError – When parameter document is of type str or CDocument and is not part of the book

  • CometError

    • On internal error

    • When the book is not open

Available:

InDesign®

CScript:

book::moveto

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:

  • str to incidate the full path to a document

  • int to indicate the document index in the book

  • CDocument to indicate a document

Returns:

The page range of the document as [start, end].

The values are 0-based.

Return type:

tuple[int, int]

Raises:
  • TypeError – When parameter types are invalid

  • ValueError – When parameter document is of type str and is empty

  • IndexError – When parameter document is of type int and is out of bounds

  • KeyError – When parameter document is of type str or CDocument and is not part of the book

  • CometError

    • On 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:

str

Raises:

CometError

  • On internal error

  • When the book is not open

Available:

InDesign®

CScript:

book::get_master

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:

  • str to incidate the full path to a document

  • int to indicate the document index in the book

  • CDocument to indicate a document

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError – When parameter document is of type str and is empty

  • IndexError – When parameter document is of type int and is out of bounds

  • KeyError – When parameter document is of type str or CDocument and is not part of the book

Available:

InDesign®

CScript:

book::set_master

CBook.repaginate(updateCrossRefs: bool = False) None

Recalculate page numbers in the book

Parameters:

updateCrossRefs (bool) –

Update crossref placeholders?

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • CometError

    • On internal error

    • When the book is not open

Available:

InDesign®

CScript:

book::repaginate

CBook.exportPDF(exportPath: str = '', styleName: str = '') None

Export the book to a PDF document

Parameters:
  • exportPath (str) –

    Full path to the export file. Folders are created automatically.

    • Empty str: Use path and name of book file with the extension pdf

  • styleName (str) –

    Name of an existing PDF export style.

    • Empty str: Use current default style

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • CometError

    • On internal error

    • When the book is not open

Available:

InDesign®

CScript:

book::export_

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?

    • False: No, close documents without saving

    • True: Yes, save changes to documents

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • CometError

    • On internal error

    • When the book is not open

Available:

InDesign®

CScript:

book::all_documents_do

Special methods

CBook.__repr__() str

String representation.

Returns:

<CBook> Path: Path | Document count: Document count

Document 0: Document 0 name

[Document n: Document n name]

Example
<CBook> Path: C:\Temp\Book.indb | Document count: 2
Document 0: First document
Document 1: Second document

Return type:

str