2 Replies Latest reply on Feb 23, 2012 11:17 AM by B4stien

    Grouping PageItems


      Hi everyone,


      I'm struggeling with this problem, I'm trying to group 2 PageItems, one of them is a TextFrame, while the second can be a Story, an Image or a PDF. I add those items programmatically on the page and then try to group them:


      function insertFile(file:File, description:String, page:Page):void{

        var placedObject:Object = page.place(file);

        var myTextFrame:TextFrame = page.textFrames.add();

        var objectBounds:Object = placedObject.geometricBounds;

        myTextFrame.geometricBounds = [objectBounds[2], objectBounds[1], objectBounds[2] + 5, objectBounds[3]];

        myTextFrame.contents = description;

        page.groups.add([myTextFrame, placedObject]);



      Unfortunatelly this fails and returns: Invalid parameter at the "page.groups.add([myTextFrame, placedObject]);" line.


      I've tried to call a Javascript script with the pageItems ids as argument instead, but the script can't find the "placedObject" in the list of pageItems.


      InDesign.app.doScript(file, ScriptLanguage.JAVASCRIPT, [''+myTextFrame.id, ''+placedObject.id]); // => alerts: Given ids: 302, 276 - Available ids: 302, 271



      If I try to fetch the placedObject via its id in my method it finds it, but the groups.add still fails:


      var placedItem:PageItem = page.pageItems.itemById(placedObject.id);



      I've also tried to create 2 TextFrames and group them, and this works. So there seem to be something wrong with my placedObject, but I can't figure out what. Does anyone has a clue?

      Thanks for your help.


      -- Bastien

        • 1. Re: Grouping PageItems
          absqua Level 4

          In JavaScript, anyway, place() returns an array whose members are the images, pdfs, or whatever. You can't add those to groups; you have to add their parent rectangles. So, again in JavaScript, it would need to look like:


          var placedObject  = page.place(file)[0].parent;


          You should be able to group that.



          • 2. Re: Grouping PageItems
            B4stien Level 1

            Thanks big time Jeff! Using the parent works.


            (In ActionScript place() returns an array as well, I just forgot it in my example)