🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
5 messages
5 total messages Started by stefan123 Thu, 02 Apr 2009 16:19
[JS] checking type of pageItem
#131
Author: stefan123
Date: Thu, 02 Apr 2009 16:19
10 lines
952 bytes
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
Re: [JS] checking type of pageItem
#132
Author: Kasyan_Servetsky
Date: Thu, 02 Apr 2009 16:35
1 lines
747 bytes
alert(app.activeDocument.pageItems.item(0).getElements()[0].constructor.name);
Re: [JS] checking type of pageItem
#133
Author: stefan123
Date: Thu, 02 Apr 2009 16:36
5 lines
797 bytes
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?????
Re: [JS] checking type of pageItem
#137
Author: Kasyan_Servetsky
Date: Thu, 02 Apr 2009 17:20
8 lines
1464 bytes
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); }
Re: checking type of pageItem
#140
Author: pd
Date: Thu, 02 Apr 2009 19:59
18 lines
1806 bytes
On Apr 2, 12:19 pm, stefan...@adobeforums.com wrote:
> 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

For InDesign CS4, I think the preferred way is:

var type = myPageItem.reflect.name;
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads