comet.file¶
The file module provides file related helper methods.
Methods¶
- comet.file.download(URL, path, replaceExisting=False, options=[])¶
Load a file defined by an URL. The new file or folder will get name which is specified in the target path. cURL is used for the download.
- Parameters:
URL (str) – Complete URL to download
path (str) – Full target path
replaceExisting (bool) – When the target already exists, should it be overwritten?
options (dict[str, int | str | list[str]]) –
Additional cURL options.
Keys must bestr
. Value types depend on the provided keys.
The data type Path is also astr
but with the addition that $-Aliases at the beginning of the path are automatically replaced.
Global and Database tags like <folder> or <sessionId> instr
and Path values are automatically replaced by their current values.
A full description of cURL parameter can be found here.
- Return type:
None
- Raises:
TypeError – When parameter types are invalid
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- comet.file.downloadWebImages(URLs, target=None, flags=0)¶
Parallel download of a list of Web Images.Parallel processing vastly speeds up the download process compared to loading the images individually.
Can be used to preload images e.g. before a product build-up to speed up the building process, if the images are known beforehand.
The images are stored in the same file that is used for the Web Images of a document. The //// URL markers supported in Web Images are supported here aswell.
If the URLs contain passwords, the option ‘kNoHash’ should be used, as the encryption of the passwords produces different results with each call and accordingly the hash code generated from the encrypted URL produces different file names with each call, even if the URL does not change.
If this function is used, it makes sense to make subsequent calls to
CFrame.setImage()
with the value 16 (suppress checking header) in the option ‘kUpdateFlags’.- Parameters:
- Returns:
A list of results containing [URL, Local result file, Error Code]
- Return type:
- Raises:
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- comet.file.PDFCountPages(path, usePDFLib=False)¶
- Parameters:
path (str) – Full path to a PDF file.
usePDFLib (bool) –
Use PDFlib for querying?
WhenTrue
PDFLib is used for querying the page count.
The use of PDFlib is subject to licensing. You will need a PDFlib + PDI license for PDFlib 10. Licenses can be purchased here. The license file must have the name licensekeys.txt and be located in the Plug-Ins folder of your InDesign® resp. in the program folder of comet_pdf.Illustrator® Not supported.
- Returns:
The number of pages in the provided PDF.
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter path is empty
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- comet.file.getDataFile(ID, enabledOnly=True, autoResolve=True)¶
Get the (relative) path of a data file definition.
- Parameters:
- Returns:
(Relative) path of the data file alias.
- Return type:
- Raises:
TypeError – When parameter types are invalid
KeyError –
When no entry is found.
When a deactivated entry is found, but parameter enabledOnly is
True
.
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- comet.file.setDataFile(ID, value, stage=0, enabledOnly=False)¶
Change the path definition of a data file definition. If the entry is shown in the Settings panel list, this entry is also changed. File paths are automatically converted to relative paths if the file is located in the following folders:
Current desktop : $DESKTOP/…
Current document folder : $DOCUMENTS/…
Home directory : $HOME/…
Plug-ins folder : $PLUGINS/…
Comet plug-ins : $COMET/…
Comet cache : $CACHE/…
User settings folder : $PREFS/…
XML folder : $COMETDATA/…. In database and SOAP connections equal to $CACHE/…
- Parameters:
value (str) – New value that is assigned to the entry. Incomplete path specifications always refer to the currently set data folder.
stage (int) –
At which level should the path definition be changed?
0: Global. The definition is changed for all users in the data pool. The change takes effect immediately. This option is not supported in PubServer connections!
1: Local. The definition is changed locally and displayed in red in the ‘Settings’ panel. The entry remains unchanged in the data pool. This option has no effect in PubServer connections!
- 2: Temporary. Only defined in batch jobs! Create or change a temporary definition of the given alias name. The specification of an ID is not supported here! The entries are not shown in the Settings panel! In contrast to local changes, this definition is also effective in PubServer connections.
The definition covers definitions of the same name in the datapool. It is removed again when the data connection is disconnected. The definitions $DESKTOP, … must not be changed with the function!
Illustrator® Not supported.
enabledOnly (bool) –
Change entry only if it is active? This information is particularly important if there are several entries with the same alias name.
- Return type:
None
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter stage has invalid value
KeyError –
When no entry is found.
When a deactivated entry is found, but parameter enabledOnly is
True
.
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript: