comet.CBook

class comet.CBook

CBook represents an opened InDesign® book.

See also

Module book

Book access and queries

Methods

CBook.isValid()

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()

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()

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()

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=True)

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()

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, index=-1, repaginate=True, updateCrossRefs=False)

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, repaginate=True, updateCrossRefs=False)

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)

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, index, repaginate=True, updateCrossRefs=False)

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)

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()

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)

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=False)

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='', styleName='')

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_

Special methods

CBook.__repr__()

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