3 Replies Latest reply on Jul 18, 2013 7:43 AM by Peter Kahrel

    How to process nested groups

    John Kriho Level 1

      Hi,

       

      I'd like to write a script that will process all groups within a document, but it must support nested groups (groups that contain other groups).

       

      I only want to process the outermost, encompassing group, and I will need access to all of the page items with the group (including those contained within the inner groups).

       

      Experimenting, it looks like if you request the list of groups for the document, you get only the outermost encompassing groups, which would be ideal for my purposes.

       

      The only anomoly is that if you process all of the page items for the document instead, that actually lists all of the groups, not just the outermost ones.

       

      As an example, consider a document with 3 text frames (A,B,C) and 2 groups (1,2). Frames A and B are grouped, forming group 1, and group 1 is further grouped with text frame C, forming group 2, which is the outermost encompassing group:

       

         // The following code returns all 5 page items, (3 text frames and 2 groups).

         var theItems = app.documents[0].allPageItems;

         

         // The following code returns 1 item, which is the outermost encompassing group (group 2)

         var theItems = app.documents[0].groups;

       

      Is this as expected?

       

      Thanks.