Skip to content

PageItems

app.activeDocument.pageItems

A collection of PageItem objects. Provides complete access to all the art items in an Illustrator document in the following classes:

You can reference page items through the PageItems property in a Document, Layer, or GroupItem.

When you access an individual item in one of these collections, the reference is a page item of one of a particular type. For example, if you use PageItems to reference a graph item, the typename value of that object is GraphItem.


app.activeDocument.pageItems.length

The number of objects in the collection.

Number; read-only.


app.activeDocument.pageItems.parent

The parent of this object.

Object; read-only.


app.activeDocument.pageItems.typename

The class name of the referenced object.

String; read-only.


app.activeDocument.pageItems.getByName(name)

Gets the first element in the collection with the specified name.

ParameterTypeDescription
nameStringName of element to get

PageItem


app.activeDocument.pageItems.index(itemKey)

Gets an element from the collection.

ParameterTypeDescription
itemKeyString, NumberString or number key

PageItem


app.activeDocument.pageItems.removeAll()

Deletes all elements in this collection.

Nothing.


Getting references to external files in page items

Section titled “Getting references to external files in page items”
// Gets all file-references in the current document using the pageItems object,
// then displays them in a new document
if (app.documents.length > 0) {
var fileReferences = new Array();
var sourceDoc = app.activeDocument;
for (var i = 0; i < sourceDoc.pageItems.length; i++) {
var artItem = sourceDoc.pageItems[i];
switch (artItem.typename) {
case "PlacedItem":
fileReferences.push(artItem.file.fsName);
break;
case "RasterItem":
if (!artItem.embedded) {
fileReferences.push(artItem.file.fsName);
}
break;
}
}
// Write the file references to a new document
var reportDoc = documents.add();
var areaTextPath = reportDoc.pathItems.rectangle(reportDoc.height, 0, reportDoc.width, reportDoc.height);
var fileNameText = reportDoc.textFrames.areaText(areaTextPath);
fileNameText.textRange.size = 24;
var paragraphCount = 3;
var sourceName = sourceDoc.name;
var text = "File references in \'" + sourceName + "\':\r\r";
for (i = 0; i < fileReferences.length; i++) {
text += (fileReferences[i] + "\r");
paragraphCount++;
}
fileNameText.contents = text;
}