Layers of an InDesign® document
Layers of an InDesign® document
static int count()
How many layers does the active document have?
Name | Type | Default | Description |
Return | int | Number of layers of the active document |
i = layer::count ();
static char* front_name(char* s)
Get the name of the active document layer.
For InDesign® (Desktop) this is the active layer of the current front document.
For InDesign® Server, the current front document is the last document opened and the active layer is the layer that was last defined by layer::select for this document. This specification is saved in the document and can also be defined with InDesign® (Desktop). The layer selection by normal InDesign® (Desktop) onboard tools is not sufficient for the call of front_name!
If the document has only one layer, this layer is automatically used as the active layer. The call of layer::select is not necessary in this case.
Name | Type | Default | Description |
Return | String or char* (Depends on parameter s) | s is returned for your convenience. Avoid calls like s = layer::front_name (s);, they don't make sense at all. | |
s | String or char* | - | reserved memory for the layer name |
char s[256] s = layer::front_name (s);
static int rename_all(char* prefix = 0)
Rename all layers. In this the passed prefix is used as the base of the layer name :
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
prefix | String or char* | "" | Name base. If the name is empty, the default name is used for the layer ('layer'). |
err_code = layer::rename ([s_prefix]);
static int sort()
Sort from layer list from top to bottom.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode |
layer::sort ();
static int index(char* n)
At which position is the layer at? Positions are counted beginning at 0 from the last layer. If a layer is not found, -1 is returned.
Name | Type | Default | Description |
Return | int | Layer position or -1. | |
n | String or char* | - | Layer name |
i = layer::index (s);
static char* name(int index, char* res)
Name of the i-th layer. Positions are counted beginning at 0 from the last layer. If there is no layer with the specified index, then - of course - the empty string will be returned.
Name | Type | Default | Description |
Return | String or char* (Depends on parameter result) | Name of the i-th layer, same as parameter res. | |
index | int | - Layer number | |
res | String or char* | - | Reserved memory for the layer name |
char s[256];
s = layer::name (i, s);
static int select_i(int index)
Activate a layer specified in your index. If the layer is not found, the method has no effect.
InDesign® Server as a faceless application cannot select a layer. The layers name is set as a document preference in this case.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
index | int | - | 0-based layer index. 0 is the uppermost layer. |
err_code = layer::select_i (i);
static int select(char* lname)
Activate a layer specified by name. If the layer is not found, the method has no effect.
InDesign® Server as a headless application cannot select a layer. The layers name is set as a document preference in this case.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
lname | String or char* | - | Name of a layer |
err_code = layer::select (nam);
static int set_visible_i(int index, int vis)
Display or hide a layer specified in your index.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
index | int | - | 0-based layer index. 0 is the uppermost layer. |
vis | int | - | != 0 visible, 0 hide |
err_code = layer::set_visible_i (index, nam);
static int set_visible(char* nam, int vis)
ZDisplay or hide a layer specified by name.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
nam | String or char* | - | Name of a layer |
vis | int | - | != 0 visible, 0 hide |
err_code = layer::set_visible (nam);
static int remove_i(int index)
Delete a layer specified in your index. By deleting a layer, all the objects located on this layer will be deleted.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
index | int | - | 0-based layer index. 0 is the uppermost layer. |
layer::remove_i (ix);
static int remove(char* nname)
Delete a layer specified by name. By deleting a layer, all the objects on this layer will be deleted.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
nname | String or char* | - | Name of a level |
layer::remove (str);
static int merge(char* from, char* to)
Copy the contents of the layer from in the layer to. Afterwards, the layer from will be deleted. If the content of the layer from is to be preserved, please use the function layer::copy.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
from | String or char* | - | Name of the layer the objects of which are to be moved |
to | String or char* | - | Name of the target layer |
err_code = layer::merge (from, to);
static int merge_ni(char* from, int to)
Copy the contents of the layer from into the layer to. Afterwards, the layer from will be deleted. If the content of the layer from is to be preserved, please use the function layer:::copy_ni.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
from | String oder char* | - | Name of the layer the objects of which are to be moved |
to | int | - | Index of the target layer |
err_code = layer::merge_ni (from, to);
static int merge_ii(int from, int to)
Copy the contents of the layer from into the layer to. Afterwards, the layer from will be deleted. If the content of the layer from is to be preserved, please use the function layer::copy_ii.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
from | int | - | Index of the layer the objects of which are to be moved |
to | int | - | Index of the target layer |
err_code = layer::merge_ii (from, to);
static int merge_in(int from, char* to)
Copy the contents of the layer from into the layer to. Afterwards, the layer from will be deleted. If the content of the layer from is to be preserved, please use the function layer::copy_in.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
from | int | - | Index of the layer the objects of which are to be moved |
to | String or char* | - | Name of the target layer |
err_code = layer::merge_in (from, to);
static int copy(
char* from,
char* to,
int exhaustive = 0,
int reconstruct = 0,
int completeProducts = 0)
Copy the contents of the layer from into the layer to.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
from | String or char* | - | Index of the layer the objects of which are to be moved |
to | String or char* | - | Name of the target layer |
exhaustive | int | 0 | Due to ab bug in InDesign® Server CS6 the Server may crash while executing this command.
Set exhaustive to 1 to avoid this error - we use a by pass in this case. 0 : default behavior 1 : use the bypass |
reconstruct | int | 0 | Recreate Comet groups, relink Comet notes and re-map repetition elements for the new frames? 0 : no 1 : yes Hidden Comet notes are NOT duplicated! |
completeProducts | int | 0 | In case there are page items beloning to a Comet group and NOT laying on the layer from, duplicate this page items too. 0 : no 1 : yes |
Duplicate the current front layer and recreate all Comet groups.
int main () { char frontname [4000]; char newname [4000]; char tmp [4000]; int index = 0;
// Get current front layer layer::front_name (frontname); index = layer::index (frontname);
// Create a new layer name and create the layer layer::default_name (sprintf (tmp, "%s Kopie", frontname), newname); layer::add_i (newname, index+1);
// Copy content layer::copy (frontname, newname, 1, 1);
return 0; }
static int copy_ni(
char* from,
int to,
int exhaustive = 0,
int reconstruct = 0,
int completeProducts = 0)
Copy the contents of the layer from into the layer to.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
from | String or char* | - | Index of the layer the objects of which are to be moved |
to | int | - | Name of the target layer |
exhaustive | int | 0 | Due to ab bug in InDesign® Server CS6 the Server may crash while executing this command.
Set exhaustive to 1 to avoid this error - we use a by pass in this case. 0 : default behavior 1 : use the bypass |
reconstruct | int | 0 | Recreate Comet groups, relink Comet notes and re-map repetition elements for the new frames? 0 : no 1 : yes Hidden Comet notes are NOT duplicated! |
completeProducts | int | 0 | In case there are page items beloning to a Comet group and NOT laying on the layer from, duplicate this page items too. 0 : no 1 : yes |
static int copy_ii(
int from,
int to,
int exhaustive = 0,
int reconstruct = 0,
int completeProducts = 0)
Copy the contents of the layer from into the layer to.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
from | int | - | Index of the layer the objects of which are to be moved |
to | int | - | Index of the target layer |
exhaustive | int | 0 | Due to ab bug in InDesign® Server CS6 the Server may crash while executing this command.
Set exhaustive to 1 to avoid this error - we use a by pass in this case. 0 : default behavior 1 : use the bypass |
reconstruct | int | 0 | Recreate Comet groups, relink Comet notes and re-map repetition elements for the new frames? 0 : no 1 : yes Hidden Comet notes are NOT duplicated! |
completeProducts | int | 0 | In case there are page items beloning to a Comet group and NOT laying on the layer from, duplicate this page items too. 0 : no 1 : yes |
static int copy_in(
int from,
char* to,
int exhaustive = 0,
int reconstruct = 0,
int completeProducts = 0)
Copy the contents of the layer from into the layer to.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
from | int | - | Index of the layer the objects of which are to be moved |
to | String or char* | - | Name of the target layer |
exhaustive | int | 0 | Due to ab bug in InDesign® Server CS6 the Server may crash while executing this command.
Set exhaustive to 1 to avoid this error - we use a by pass in this case. 0 : default behavior 1 : use the bypass |
reconstruct | int | 0 | Recreate Comet groups, relink Comet notes and re-map repetition elements for the new frames? 0 : no 1 : yes Hidden Comet notes are NOT duplicated! |
completeProducts | int | 0 | In case there are page items beloning to a Comet group and NOT laying on the layer from, duplicate this page items too. 0 : no 1 : yes |
static int move(char* mv, char* behind)
Change the sequence of the layer. The layer mv is moved behind the layer behind.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
mv | char* | - | Name of the layer which is to be moved |
behind | char* | - | Name of the layer to move the layer behind. If a layer with given name not exists, the layer will become the new front layer. |
err_code = layer::move (mv, behind);
static int move_ni(char* mv, int behind)
Change the sequence of the layer. The layer mv is moved in behinde the layer behind.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
mv | String or char* | - | Name of the layer which is to be moved |
behind | int | - | Index of the layer to move the layer behind -1 or > number of layers : The layer will become the new front layer |
err_code = layer::move (mv, behind);
static int move_ii(int mv, int behind)
Change the sequence of the layer. The layer mv is moved behinde the layer behind.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
mv | int | - | Name of the layer which is to be moved |
behind | int | - | Index of the layer to move the layer behind -1 or > number of layers : The layer will become the new front layer |
err_code = layer::move (mv, behind);
static int move_in(int mv, char* behind)
Change the sequence of the layer. The layer mv is moved behinde the layer behind.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
mv | int | - | Index of the layer which is to be moved |
behind | String or char* | - | Name of the layer to move the layer behind. If a layer with given name not exists, the layer will become the new front layer. |
err_code = layer::move (mv, behind);
static int rename(char* oldName, char* newName)
Change the name of a layer.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
oldName | String or char* | - | Name of the layer the name of which is to be changed |
newName | String or char* | - | New layer name |
err_code = layer::rename (oldName, newName);
static int rename_i(int index, char* newName)
Change the name of a layer
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
index | int | - | Index of the layer the name of which is to be changed |
newName | String or char* | - | New layer name |
err_code = layer::rename_i (ix, newName);
static int rename_prefixed(char* oldName, char* prefix)
Change the name of a layer in accordance with a specified prefix. If the prefix is specified as 'Paul' for example, there is a layer with the name 'Paul 3', 'Paul 4' will be used as the new name.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
oldName | String or char* | - | Name of the layer the name of which is to be changed |
prefix | String or char* | - | Prefix of the new layer name |
err_code = layer::rename_prefixed (oldName, prefix);
static int rename_prefixed_i(int index, char* prefix)
Change the name of a layer in accordance with a specified prefix. If the prefix is specified as 'Paul' for example, there is a layer with the name 'Paul 3', 'Paul 4' will be used as the new name.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
index | int | - | Index of the layer the name of which is to be changed |
prefix | String or char* | - | Prefix of the new layer name |
err_code = layer::rename_prefixed_i (index, prefix);
static int add(
char* newName,
char* behind,
int doSelect = 0,
char* outName = 0)
Create a new document layer behind a given layer.
Name | Type | Default | Description |
Return | int | 0 or Error Code | |
newName | String oder char* | - | Name of the new layer. If a layer already exists with the specified name
no new layer is created and the position of the existing layer remains unchanged. 0 or "" : IIf no name is give, a new default name is determined. |
behind | String oder char* | - | Name of the layer behind which the new layer should be located. If this layer is not found, the new layer will be created as the lowest layer. |
doSelect | int | 0 | Should the layer be activated immediately? 0 : no 1 : yes Ignored by Illustrator. |
outName | String oder char* | 0 | Allocated memory for the name of the newly created layer. 0 : Ignore return value |
To run the script, you need a test document with at least 3 levels, one of which must be named "Layer 6". The document should also contain four frames whose UIDs you still need to enter in the calls to the mv function.
int mv (int uid, char* l, char * bkname, int bkindex) { ItemRef fr = item::alloc (); int result = 0; String lname = string::alloc (); String lname2 = string::alloc ();
item::define (fr, 0, uid);
if (strlen (bkname)) result = layer::add (l, bkname, 0, lname); else result = layer::add_i (l, bkindex, 0, lname);
printf ("# Frame %d : (%s)\n", uid, lname);
if (result == 0) { result = frame::move_to_layer (fr, lname, 0, 0); if (result != 0) { printf ("# Layoutrule 'Move to layer' : Ignoring error %d (%s)\n", result, serror (result)); } else { printf ("LAYER of %d : (%s)\n", uid, frame::get_layer (fr, lname2)); } }
printf ("\n"); string::release (lname); string::release (lname2); item::release (fr); return 1; }
int main () { mv (262, "", "Layer 6", 0); mv (305, "YY", "Layer 6", 0);
mv (464, "", 0, 2); mv (466, "ZZ", 0, 2); return 0; }
static int add_i(
char* newName,
int index,
int doSelect = 0,
char* outName = 0)
Create a new document layer behind a layer given by its index.
Name | Type | Default | Description |
Return | int | 0 or Error Code | |
newName | String oder char* | - | Name of the new layer. If a layer already exists with the specified name
no new layer is created and the position of the existing layer remains unchanged. 0 or "" : If no name is give, a new default name is determined. |
behind | int | - | 0-based index, behind which the new level should lie. If this layer is not found, the new layer will be created as the lowest layer. |
doSelect | int | 0 | Should the layer be activated immediately? 0 : no 1 : yes Ignored by Illustrator. |
outName | String oder char* | 0 | Allocated memory for the name of the newly created layer. 0 : Ignore returned value |
To run the script, you need a test document with at least 3 levels, one of which must be named "Layer 6". The document should also contain four frames whose UIDs you still need to enter in the calls to the mv function.
int mv (int uid, char* l, char * bkname, int bkindex) { ItemRef fr = item::alloc (); int result = 0; String lname = string::alloc (); String lname2 = string::alloc ();
item::define (fr, 0, uid);
if (strlen (bkname)) result = layer::add (l, bkname, 0, lname); else result = layer::add_i (l, bkindex, 0, lname);
printf ("# Frame %d : (%s)\n", uid, lname);
if (result == 0) { result = frame::move_to_layer (fr, lname, 0, 0); if (result != 0) { printf ("# Layoutrule 'Move to layer' : Ignoring error %d (%s)\n", result, serror (result)); } else { printf ("LAYER of %d : (%s)\n", uid, frame::get_layer (fr, lname2)); } }
printf ("\n"); string::release (lname); string::release (lname2); item::release (fr); return 1; }
int main () { mv (262, "", "Layer 6", 0); mv (305, "YY", "Layer 6", 0);
mv (464, "", 0, 2); mv (466, "ZZ", 0, 2); return 0; }
static int add_prefixed(
char* prefix,
char* behind,
int doSelect = 0,
char* outName = 0)
Create a new named/prefxied document layer behind a given layer.
Name | Type | Default | Description |
Return | int | 0 or Error Code | |
prefix | String oder char* | - | Name/prefix of the new layer. If a layer already exists with the specified prefix
a new layer with the next counting number is created.
(If, for example, the prefix Lala is specified and the layers Lala, Lala 1 and Lala 30 exist, the layer Lala 31 will be created.) 0 or "" : If no name is specified, a new default name is determined. |
behind | String oder char* | - | Name of the layer behind which the new layer should be located. If this layer is not found, the new layer will be created as the lowest layer. |
doSelect | int | 0 | Should the layer be activated immediately? 0 : no 1 : yes |
outName | String oder char* | 0 | Allocated memory for the name of the newly created layer. 0 : Ignore returned value |
static int add_prefixed_i(
char* prefix,
int behind,
int doSelect = 0,
char* outName = 0)
Create a new named/prefxied document layer given by its index.
Name | Type | Default | Description |
Return | int | 0 or Error Code | |
prefix | String oder char* | - | Name/prefix of the new layer. If a layer already exists with the specified prefix
a new layer with the next counting number is created.
(If, for example, the prefix Lala is specified and the layers Lala, Lala 1 and Lala 30 exist, the layer Lala 31 will be created.) 0 or "" : If no name is specified, a new default name is determined. |
behind | int | - | 0-based index behind which the new layer should be located. If this layer is not found, the new layer is created as the lowest layer. |
doSelect | int | 0 | Should the layer be activated immediately? 0 : no 1 : yes |
outName | String oder char* | 0 | Allocated memory for the name of the newly created layer. 0 : Ignore returned value |
static char* default_name(char* prefix, char* newName)
Ascertain the next valid default name which can be used for the new layer. If the prefix is empty, InDesign® determines the name. If a prefix is specified, a number is attached to the prefix. If the document has 999 layers, the method is abandoned.
Name | Type | Default | Description |
Return | String or char* (Depends on parameter result) | Ascertained default name. Same as parameter newName. | |
prefix | String or char* | - | Prefix for the determination of the layer name. As an expansion he first free number is used which is not yet in use. At 999 the method is abandoned. |
newName | String or char* | - | Reserved memory for the return |
newName = layer::default_name (prefix, newName);
static int get_visible_i(int index)
Is the given layer visible or not?
Name | Type | Default | Description |
Return | int | 1 : visible 0 : hidden |
|
index | int | - | 0-based layer index. 0 is the uppermost layer. |
static int get_visible(char* name)
Is the given layer visible or not?
Name | Type | Default | Description |
Return | int | 1 : visible 0 : hidden |
|
name | String or char* | - | Name of the layer |
static int get_lock_i(int index)
Is the given layer locked or not?
Name | Type | Default | Description |
Return | int | 1 : locked 0 : unlocked |
|
index | int | - | 0-based layer index. 0 is the uppermost layer. |
static int get_lock(char* name)
Is the given layer locked or not?
Name | Type | Default | Description |
Return | int | 1 : locked 0 : unlocked |
|
name | String or char* | - | name of the layer |
static int lock_i(int index)
Lock a index given layer.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
index | int | - | 0-based layer index. 0 is the uppermost layer. |
static int lock(char* name)
Lock a layer by name
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
name | String or char* | - | name of the layer |
static int unlock_i(int index)
Unlock a layer by index.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
index | int | - | 0-based layer index. 0 is the uppermost layer. |
static int unlock(char* name)
Lock a named layer.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
name | String oder char* | - | name of the layer |
static char* get_name(ItemRef frameRef)
Find out the layer name of a given document frame.
Name | Type | Default | Description |
Return | char* | Name of layer
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. |
|
frameRef | ItemRef | - | valid doc frame |
Show the layer of the script frame
showmessage (layer::get_name (gFrame));
static int get_index(ItemRef frameRef)
Find out the layer index of a given document frame. The top most layer has the index 0. In the layers panel this is the last entry.
Name | Type | Default | Description |
Return | int | 0-based layer index. The top most layer has the index 0. In the layers panel this is the last entry. | |
frameRef | ItemRef | - | valid doc frame |
Show the layer index of the script frame
showmessage ("%d", layer::get_index (gFrame));
static int get_printable(char* lname)
Is a given layer printable?
Name | Type | Default | Description |
Return | int | 1 : layer is printable 0 : error or not printable |
|
lname | String or char* | - | Name of the layer |
int main () { char * lname = "Ebene 2"; int state = layer::get_printable (lname); wlog ("", "%s : %d\n", lname, state); layer::set_printable (lname, !state); wlog ("", "%s : %d\n", lname, layer::get_printable (lname)); return 0; }
static int set_printable(char* lnamem, int state = 1)
Set the printability of a layer.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode | |
lname | String or char* | - | Name of the layer |
state | int | 1 | printability 0 : Layer is not printable 1 : Layer is printable |
int main () { char * lname = "Ebene 2"; int state = layer::get_printable (lname); wlog ("", "%s : %d\n", lname, state); layer::set_printable (lname, !state); wlog ("", "%s : %d\n", lname, layer::get_printable (lname)); return 0; }
static int get_ui_color()
Get the name of the color of a layer of the front document. The color names are the fixed Stock colors integrated in InDesign as displayed in the 'Layer options' dialog. Custom colors are returned in the format "RGB r g b" with r, g, b ∈ [0-255].
Custom colors are not supported by comet_pdf!
The function has been implemented for internal use only. There are currently no set function yet.
Alphabetic index HTML hierarchy of classes or Java