Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[JS] checking type of pageItem

New Here ,
Apr 02, 2009 Apr 02, 2009
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
TOPICS
Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 02, 2009 Apr 02, 2009
alert(app.activeDocument.pageItems.item(0).getElements()[0].constructor.name);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 02, 2009 Apr 02, 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?????
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 02, 2009 Apr 02, 2009
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 02, 2009 Apr 02, 2009
LATEST
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);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines