Adobe 0046100128056 Scripting Guide - Page 54

Assigning items to layers, Setting layer properties, Working with layer guides

Page 54 highlights

CHAPTER 4: Working with Layers Scripting Layers 54 Assigning page items to layers You can assign a page item to a layer by either referring to the layer when you create the page item (the add method of all page items can take a layer as a parameter) or setting the itemLayer property of an existing page item. The following script fragment shows how to assign a page item to a layer using both techniques. (For the complete script, see AssignPageItemsToLayers.) //Given a reference to a page "myPage," and a document "myDocument," //create a text frame on a layer named "TextFrames" var myTextFrame = myPage.textFrames.add(myDocument.layers.item("TextFrames")); myTextFrame.geometricBounds = [72, 72, 144, 144]; //Create a rectangle on the current target layer. var myRectangle = myPage.rectangles.add({geometricBounds:[72, 144, 144, 216]}); //Move the rectangle to a specific layer. myRectangle.itemLayer = myDocument.layers.item("Rectangles"); //Create a series of ovals. for(var myCounter = 72; myCounter < 172; myCounter+=10){ myPage.ovals.add({geometricBounds:[216, myCounter, 226, myCounter+10]}); } //Move all of the ovals on the page to a specific layer. myPage.ovals.everyItem().itemLayer = myDocument.layers.item("Ovals"); Setting layer properties Layer properties control the layer name, color, visibility, and other attributes of a layer. This section shows how to work with layer properties. Setting basic layer properties Basic layer properties include the name of the layer, the highlight color of the layer, the visibility of the layer, and whether text objects on the layer ignore text-wrap settings. The following script fragment shows how to set these basic properties of a layer. (For the complete script, see BasicLayerProperties.) //Given a document "myDocument"... var myLayer = myDocument.layers.add(); myLayer.name = "myLayer"; myLayer.layerColor = UIColors.CHARCOAL; myLayer.ignoreWrap = false; myLayer.visible = true; Working with layer guides Guides can be assigned to a specific layer, just like page items. You can choose to show or hide the guides for a layer, and you can lock or unlock the guides on a layer. The following script fragment shows how to work with the guides on a layer. (For the complete script, see LayerGuides.) //Given a document "myDocument" and a page "myPage" containing at least one guide... //Create a new layer. var myLayer = myDocument.layers.add(); //Move all of the guides on the page to the new layer. myPage.guides.everyItem().itemLayer = myLayer; myLayer.lockGuides = true; myLayer.showGuides = true;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209

C
HAPTER
4: Working with Layers
Scripting Layers
54
Assigning page items to layers
You can assign a page item to a layer by either referring to the layer when you create the page item (the
add
method of all page items can take a layer as a parameter) or setting the
itemLayer
property of an
existing page item. The following script fragment shows how to assign a page item to a layer using both
techniques. (For the complete script, see AssignPageItemsToLayers.)
//Given a reference to a page "myPage," and a document "myDocument,"
//create a text frame on a layer named "TextFrames"
var myTextFrame = myPage.textFrames.add(myDocument.layers.item("TextFrames"));
myTextFrame.geometricBounds = [72, 72, 144, 144];
//Create a rectangle on the current target layer.
var myRectangle = myPage.rectangles.add({geometricBounds:[72, 144, 144, 216]});
//Move the rectangle to a specific layer.
myRectangle.itemLayer = myDocument.layers.item("Rectangles");
//Create a series of ovals.
for(var myCounter = 72; myCounter < 172; myCounter+=10){
myPage.ovals.add({geometricBounds:[216, myCounter, 226, myCounter+10]});
}
//Move all of the ovals on the page to a specific layer.
myPage.ovals.everyItem().itemLayer = myDocument.layers.item("Ovals");
Setting layer properties
Layer properties control the layer name, color, visibility, and other attributes of a layer. This section shows
how to work with layer properties.
Setting basic layer properties
Basic layer properties include the name of the layer, the highlight color of the layer, the visibility of the
layer, and whether text objects on the layer ignore text-wrap settings. The following script fragment shows
how to set these basic properties of a layer. (For the complete script, see BasicLayerProperties.)
//Given a document "myDocument"...
var myLayer = myDocument.layers.add();
myLayer.name = "myLayer";
myLayer.layerColor = UIColors.CHARCOAL;
myLayer.ignoreWrap = false;
myLayer.visible = true;
Working with layer guides
Guides can be assigned to a specific layer, just like page items. You can choose to show or hide the guides
for a layer, and you can lock or unlock the guides on a layer. The following script fragment shows how to
work with the guides on a layer. (For the complete script, see LayerGuides.)
//Given a document "myDocument" and a page "myPage" containing at least one guide...
//Create a new layer.
var myLayer = myDocument.layers.add();
//Move all of the guides on the page to the new layer.
myPage.guides.everyItem().itemLayer = myLayer;
myLayer.lockGuides = true;
myLayer.showGuides = true;