Using the InDesign® Libraries.
Using the InDesign® Libraries. Opening and closing the InDesign® libraries. Library contents (assets) can be inserted at user-defined points in the document.
static Library open(char* path)
Opening the library. It's okay if the library is already opened.
Name | Type | Default | Description |
Return | Library | Pointer to the library or 0 | |
path | String oder char* | - | Path to the library document. If the path is not complete, the folder of the current front document is used as the base. |
static int close(Library lib, int slot = 0)
Close a library. All assets from this library defined in the script becoming invalid at this point.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
lib | Library | - | With library::open cursor returned for opened library |
static int count_assets(Library lib)
number of assets of a library.
Name | Type | Default | Description |
Return | int | <=0 : Error >0 : Number of assets in library |
|
lib | Library | - | With library::open cursor returned for opened library |
Write infos abou all assest of a library to the log. Take care to release the asset reference at the end of every loop.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek2.indl"); Asset asset = 0; int i;
if (!lib) { showerror ("Cannot open library"); return 0; }
for (i = 0; i < library::count_assets (lib); i++) { asset = library::asset::get_nth (lib, i);
wlog ("", "# Asset %d\n", i+1); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset); }
return 0; }
static char* get_path(Library lib)
Complete path of an open library.
Name | Type | Default | Description |
Return | char* | Complete path of the given library. "" : In case of an error The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values. |
|
lib | Library | - | Reference of an open library |
Open a library in a panel.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl");
if (lib) wlog ("", "# Libpath : '%s'\n", library::get_path (lib));
return 0; }
static Asset add_asset(Library lib, ItemList frames)
Create a new asset. Use the library::asset::set_ functions to define the assets meta data.
Name | Type | Default | Description |
Return | Asset | New created reference to the asset. If you do not need anymore, please release it by using library::asset::release. | |
lib | Library | - | Reference of an open library |
frames | ItemList | - | valid and non empty list of frames. All frames must be on the same page of a document. |
The currently selected frames are added as a new asset to a library.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek2.indl"); ItemList frames = itemlist::selected (); Asset asset = 0;
if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::add_asset (lib, frames); wlog ("", "# Add asset %d\n", asset);
library::asset::set_name (asset, "My new Asset"); library::asset::set_description (asset, "Asset created by cScript");
library::asset::release (asset);
return 0; }
static Asset asset::get(Library lib, char* name)
Get a library asset by its (case insensitive) name. Names in InDesign® libraries must not be unique!
Name | Type | Default | Description |
Return | Asset | New created reference to the asset. If you do not need anymore, you must release it by using library::asset::release. | |
lib | Library | - | Valid reference to an open library |
name | String or char* | - | Case insensitive asset name. Names in InDesign® libraries do not have to be unique! |
Code snippet to demonstrate the use of assets.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
// // your code //
library::asset::release (asset); return 0; }
static int get_nth(Library lib, int n)
number of assets of a library.
Name | Type | Default | Description |
Return | Asset | New created reference to the asset. If you do not need anymore, you must release it by using library::asset::release. | |
lib | Library | - | With library::open cursor returned for opened library |
n | int | - | Index of asset. Assets are sorted by their creation date/time. |
Write infos abou all assest of a library to the log. Take care to release the asset reference at the end of every loop.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek2.indl"); Asset asset = 0; int i;
if (!lib) { showerror ("Cannot open library"); return 0; }
for (i = 0; i < library::count_assets (lib); i++) { asset = library::asset::get_nth (lib, i);
wlog ("", "# Asset %d\n", i+1); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset); }
return 0; }
static Library asset::get_lib(Asset ast)
Get the library of an asset.
Name | Type | Default | Description |
Return | Library | Reference to a library | |
ast | Asset | - | Valid asset reference |
static int asset::release(Asset ast)
Release the memory allocated by an asset. The asset itself is left untouched of course.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
ast | Asset | - | Valid asset reference |
static int asset::place(
Asset ast,
ItemRef docRef,
int pg,
char* layer = "",
float x = 0.0,
float y = 0.0,
ItemList inserted = 0)
Place an asset into a document.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
ast | Asset | - | Valid asset reference |
docRef | ItemRef | - | Destination document 0 : current front document |
pg | int | - | 1-based page number |
layer | String or char* | 0 | layer name |
x, y | float, float | 0.0, 0.0 | Position to place in points |
inserted | ItemList | 0 | Inserted frames (on successful return) 0 : ignore otherwise : With itemlist::alloc allocated ItemlIst |
Place an asset into the document.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0; int pg = 1; char * layer = "My layer"; float x = 123.45; float y = 78.9; ItemList inserted = itemlist::alloc ();
if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
library::asset::place (asset, 0, pg, layer, x, y, inserted);
library::asset::release (asset);
return 0; }
static char* asset::get_name(Asset ast)
Get an assets name.
Name | Type | Default | Description |
Return | char* | Name of the asset. "" : In case of an error The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values. |
|
ast | Asset | - | Valid asset reference |
Write some infos about an asset to the log.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
wlog ("", "# Libpath : '%s'\n", library::get_path (lib)); wlog ("", "# Asset-Infos\n"); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset);
return 0; }
static int asset::set_name(Asset ast, char* new_name)
Set an assets name.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
ast | Asset | - | Valid asset reference |
new_name | String or char* | - | Assets new name |
Set an assets name.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
library::asset::set_name (asset, "New name");
wlog ("", "# Asset-Infos\n"); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset);
return 0; }
static char* asset::get_description(Asset ast)
Get an assets description.
Name | Type | Default | Description |
Return | char* | Description of the asset. "" : In case of an error The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values. |
|
ast | Asset | - | Valid asset reference |
Write some infos about an asset to the log.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
wlog ("", "# Libpath : '%s'\n", library::get_path (lib));
wlog ("", "# Asset-Infos\n"); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset);
return 0; }
static int asset::set_description(Asset ast, char* new_descr)
Set an assets description.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
ast | Asset | - | Valid asset reference |
new_descr | String or char* | - | Assets new description |
Set an assets description.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
library::asset::set_description (asset, "New descr");
wlog ("", "# Asset-Infos\n"); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset);
return 0; }
static int asset::get_usertype(Asset ast)
Get an assets user type.
Name | Type | Default | Description |
Return | int | -1 : Error 0 : Image 1 : EPS 2 : PDF 3 : Geometry 4 : Page 5 : Text 6 : Structurs 7 : InDesign® document |
|
ast | Asset | - | Valid asset reference |
Write some infos about an asset to the log.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
> if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
wlog ("", "# Libpath : '%s'\n", library::get_path (lib));
wlog ("", "# Asset-Infos\n"); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset);
return 0; }
static int asset::set_usertype(Asset ast, int newType)
Set an assets user type.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
ast | Asset | - | Valid asset reference |
newType | int | - | Assets new user type 0 : Image 1 : EPS 2 : PDF 3 : Geometry 4 : Page 5 : Text 6 : Structurs 7 : InDesign® document |
Set an assets user type.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
> if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
library::asset::set_usertype (asset, 1);
wlog ("", "# Asset-Infos\n"); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset);
return 0; }
static char* asset::get_creationtime(Asset ast, int fmt)
Get create date/time of an asset.
Name | Type | Default | Description |
Return | char* | Creation time of the asset. "" : In case of an error The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values. |
|
ast | Asset | - | Valid asset reference |
fmt | int | - | Format specification system depended kShortDate (= 0) kLongDate (= 1) kAbbrevDate (= 2) kShortTime (= 20) kLongTime (= 36) kShortDateTime (= 16) kLongDateTime (= 17) kAbbrevDateTime (= 18) kShortDateLongTime (= 32) kLongDateLongTime (= 33) kAbbrevDateLongTime (= 34) system undependend ddmmyyyy (= 96) ddmmyyyy_hhmm (= 97) ddmmyyyy_hhmmss (= 98) dmyy (= 99) hhmm (= 100) hhmmss (= 101) hmm (= 102) hmmss (= 103) |
Write some infos about an asset to the log.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
> if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
wlog ("", "# Libpath : '%s'\n", library::get_path (lib));
wlog ("", "# Asset-Infos\n"); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset);
return 0; }
static int asset::set_creationtime(Asset ast, char* dt)
Set an assets creation date and time.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
ast | Asset | - | Valid asset reference |
⇨ datetime string | |||
dt | String or char* | - | Valid datetime string |
⇨ datetime components | |||
d, m, y | int, int, int | - | day, month, year |
h, mm, s | int, int, int | - | hour, minutes, seconds |
Set an assets creation date and time.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
> if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
library::asset::set_creationtime (asset, 26, 11, 2008, 19, 10, 12);
wlog ("", "# Asset-Infos\n"); wlog ("", "# Name : %s\n", library::asset::get_name (asset)); wlog ("", "# Descr : %s\n", library::asset::get_description (asset)); wlog ("", "# Usertype : %d\n", library::asset::get_usertype (asset)); wlog ("", "# Creation : %s\n", library::asset::get_creationtime (asset, 98));
library::asset::release (asset);
return 0; }
static Image get_preview(Asset ast, int sz = 200)
Get an assets previews. A document must be opened to execute this function.
Name | Type | Default | Description |
Return | Image | New created image reference or 0 in case of some errors. Don't forget to release created image references by using image::release at the end of your work. |
|
ast | Asset | - | Valid asset reference |
sz | int | 200 | Size of preview in pixel 0 : Origina size |
Create an assets preview and save it as jpg file.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek2.indl"); Asset asset = 0; Image img = 0;
if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
img = library::asset::get_preview (asset, 500); if (img) { image::save (img, "$DESKTOP/aaa/bbb/My Asset.jpg", 1); image::release (img); }
library::asset::release (asset);
return 0; }
static int asset::update(Asset ast, ItemList frames)
Change an assets content.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
ast | Asset | - | Valid asset reference |
frames | ItemList | - | valid and non empty list of frames. All frames must be on the same page of a document. |
Set the current frame selection to an asset.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek2.indl"); ItemList frames = itemlist::selected (); Asset asset = 0;
if (!lib) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
library::asset::update (asset, frames);
library::asset::release (asset);
return 0; }
static int asset::copy(Asset ast, Library dest_lib)
Copy an asset from one library to an other. Take care : Names of assets of InDesign® libraries must not be unique. If you want to have unique names, your script must handle this.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
ast | Asset | - | Valid asset reference |
dest_lib | Library | - | library to copy in |
Copy an asset from one library to an other.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek2.indl"); Library lib_dest = library::open ("$DESKTOP/Bibliothek.indl"); Asset asset = 0;
if (!lib || !lib_dest) { showerror ("Cannot open library"); return 0; }
asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
library::asset::copy (asset, lib_dest);
library::asset::release (asset);
return 0; }
static int asset::remove(Asset ast)
Remove an asset from its library. This action is not undoable!
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
ast | Asset | - | Valid asset reference |
Remove an asset from its library.
int main () { Library lib = library::open ("$DESKTOP/Bibliothek2.indl"); Asset asset = 0;
if (!lib) { showerror ("Cannot open library"); return 0; } asset = library::asset::get (lib, "My Asset"); if (!asset) { showerror ("Asset not in library"); return 0; }
library::asset::remove (asset); library::asset::release (asset);
return 0; }
Alphabetic index HTML hierarchy of classes or Java