3 Replies Latest reply on Feb 4, 2011 2:48 PM by Marijan Tompa [tomaxxi]

    Group Selected Items [Javascript / CS3]

    kcoppock87

      This seems like it'd be an extremely easy thing to do, but I'm unable to figure it out after searching forums, google, and the scripting documentation. I'm trying to just group whatever items are selected when I run the script. Some of the things I've tried are:

       

      var document = app.activeDocument;
      var selection = document.selection;
      
      //this doesn't work, I get 'invalid parameter'
      //for the groups.add() function.
      var group = document.groups.add(selection);
      
      //same here, I get invalid parameter on groups.add()
      var itemArray = new Array;
      for (var i in selection) {
          itemArray.push(i);
      }
      var group = document.groups.add(itemArray);
      
      //also doesn't work. Debugging shows that the itemArray.push()
      //is never reached, so the isPrototypeOf isn't working like I expect.
      var itemArray = new Array;
      for (var i in selection) {
          if (i.prototype.isPrototypeOf(PageItem)) {
              itemArray.push(i);
          }
      }
      var group = document.groups.add(itemArray);
      


      Do I just have something fundamentally wrong with how I'm trying to approach this? I'm new to Javascript, I've worked a lot with Java (Don't worry, I know they're completely unrelated), but I've got a few other scripts working, this particular issue I can't seem to figure out, though.

       

      Thoughts?

       

      Thanks!