Skip to main content
New Participant
April 2, 2009
Question

[JS] checking type of pageItem

  • April 2, 2009
  • 4 replies
  • 1180 views
Hello, is there any way to check in JavaScript what is the type of some PageItem. For example I have a Rectangle, and when I try to do it that way it return useless information:

alert(app.activeDocument.pageItems.item(0).constructor.name);

The result is "PageItem" :/

In VBScript it is very easy, I can use TypeName() function, but i need this script working on MacOS.

Can anyone help me????
Thanks in advance
This topic has been closed for replies.

4 replies

Kasyan Servetsky
Brainiac
April 2, 2009
From Adobe InDesign CS2 Scripting Guide (pages 13-14)
When you are iterating through a collection, JavaScript insists that the type of the item is the type of the
collection. When you iterate through a pageItems collection, for example, the type of each item will be
PageItem, rather than Rectangle, Oval, Polygon, GraphicLine, or TextFrame. To get the specific type
of an item when you are iterating through a collection of unlike items, use the getElements() method, as
shown in the following example:

for(myCounter = 0; myCounter < app.activeDocument.pages.item(0).pageItems.length; myCounter ++){
var myPageItem = app.activeDocument.pages.item(0).pageItems.item(myCounter);
var myPageItemType = myPageItem.getElements()[0].constructor.name;
alert(myPageItemType);
}
Kasyan Servetsky
Brainiac
April 2, 2009
New Participant
April 2, 2009
OK, I've found a solution, but I'm not sure if it is always correct. I'm using:

alert(app.activeDocument.pageItems.item(0).getElements()[0].constructor.name);

Can someone more expirienced confirm this solution?????
Kasyan Servetsky
Brainiac
April 2, 2009
alert(app.activeDocument.pageItems.item(0).getElements()[0].constructor.name);