0 Replies Latest reply on Mar 8, 2011 1:33 PM by marcel.hrdina

    [JS] CS5 Add Group to Rectangle

    marcel.hrdina

      I'm trying to create a group inside a `Rectangle` page item, preferably without resorting to contents.select(); app.cut() container.select(); app.pasteInto() hackery.

       

      Please find below my progress up to the point, where I'm stuck.

       

      1. testing the concept

      var the_group = app.activeDocument.groups.add([
          app.activeDocument.textFrames.add(),
      
          app.activeDocument.rectangles.add(),
      
          app.activeDocument.groups.add([
              app.activeDocument.rectangles.add(),
              app.activeDocument.rectangle.add()        ])
           ]);
      

      Works like a charm. Creates a group containing various element. Creates it in one statement without leaving random page items scattered in document on error.

       

      Group like this can be copied and pasted into other shape via InDesign GUI. The result is a page item whose .groups.length === 1.

       

      2. try it with script

      var container = app.activeDocument.rectangles.add({
           geometricBounds: [ reasonable bounding box values ]
           });
      
      container.groups.add([
           app.activeDocument.rectangles.add(),
           app.activeDocument.rectangles.add()
           ]);
      

       

      InDesign returns an error, complaining about arguments for .groups.add method. (I can't be more precise, I write this at home and InDesign doesn't run on Linux. I wish it would)

       

      3. try something else

      var contents_one = app.activeDocument.rectangles.add();
      var contents_two = app.activeDocumen.rectangles.add();
      
      container.groups.add([contents_one, contents_two]);
      

      I'm not a huge fan of this as it leaves items from intermediate stages lying randomly in the document. It doesn't work anyway

       

      4. last attempt

      var contents_one = container.rectangles.add();

      var contents_two = container.rectangles.add();

      // This can't be achieved via GUI

      // I learned about it from Dave Saunders' post

      // on indesignsecrets.com

       

      container.groups.add([contents_one, contents_two]);

      With this failing I gave in and consulted search field on adobeforums. When I didn't find answer I decided to post this question:

       

      I can easily create a group in hierarchy 'top level'. Why can't I repeat the same thing in a Rectangle (or Ellipse or any other closed path)?

       

      Thanks for help

      Marcel