5 Replies Latest reply on Feb 5, 2015 12:28 PM by Qwertyfly...

    duplicating multiple groups?

    mgraphix99

      Hello all,

       

      I am attempting to develop a script where i have a selection of a group and it would duplicate twice along the x axis.  Then, take all the grouped items and duplicate it down the y axis 3x. 
      This is what i have so far:

       

       

       

      var myDoc = app.activeDocument;

      var myNeckLabel = myDoc.selection[0];

       

      // For loop duplicating selection, moving to the left 2x

      for (var sel=0; sel<[2]; sel++){

        myNeckLabel.duplicate();

        myNeckLabel.translate(-3.9327*72);

      }

       

      // For loop duplicate selection down 3x

      for (var sel=0; sel<[3]; sel++){

        myNeckLabel.duplicate();

        myNeckLabel.translate(0,-3.153*72);

      }

       

       

      What the above produced for me is the desired effect, except it will only do it down the left column, so i would have the top row and the left column filled out. how do i select every object the first loop creates and then feed it into the second loop?
      Thanks for the help in advance !

        • 1. Re: duplicating multiple groups?
          Qwertyfly... Level 4

          my solution was to group the top row then continue

           

          var myDoc = app.activeDocument;
          var myNeckLabel = myDoc.selection[0];
          
          // For loop duplicating selection, moving to the left 2x
          for (var sel=0; sel<[2]; sel++){
            myNeckLabel.duplicate();
            myNeckLabel.translate(-3.9327*72);
          }
          var newSelection = myDoc.selection;
          var newGroup = myDoc.groupItems.add();
          for(var i = 0; i < newSelection.length; i++)
          {
              newSelection[i].move(newGroup,ElementPlacement.INSIDE);
           }
          // For loop duplicate selection down 3x
          for (var sel=0; sel<[3]; sel++){
            newGroup.duplicate();
            newGroup.translate(0,-3.153*72);
          }
          
          • 2. Re: duplicating multiple groups?
            mgraphix99 Level 1

            Thanks imagecollection ! putting into a group worked.
            this is what i ended up doing with the code:

             

            var myDoc = app.activeDocument;

            var myNeckLabel = myDoc.selection[0];

             

             

            // For loop duplicating selection, moving to the left 2x

            for (var sel=0; sel<[2]; sel++){

              myNeckLabel.duplicate();

              myNeckLabel.translate(-3.9327*72);

            }

            var newSelection = myDoc.selection;

            var newGroup = myDoc.groupItems.add();

            for(var i = 0; i < newSelection.length; i++)

            {

                newSelection[i].move(newGroup,ElementPlacement.INSIDE);

            }

            // For loop duplicate selection down 3x

            for (var sel=0; sel<[3]; sel++){

              newGroup.duplicate();

              newGroup.translate(0,-3.153*72);

            }

             

            var totalMatrix = app.getScaleMatrix(-100,100);

            var allSelected = myDoc.selection;

            var wholeGroup = myDoc.groupItems.add()

            for (var i = 0; i < allSelected.length;i++)

            {

                allSelected[i].move(wholeGroup,ElementPlacement.INSIDE);

            }

            app.activeDocument.activeLayer.pageItems[0].transform(totalMatrix);

             

             

            By chance do you know what the best way for me to do this without grouping everything into one massive object?

             

            I tried aciveDocument.selectObjectsOnActiveArtboard(true);  but it didn't work out.

             

            Thanks again for the help

            • 3. Re: duplicating multiple groups?
              Qwertyfly... Level 4

              Does this do what you want?

              var doc = app.activeDocument;  
              var sel = doc.selection;  
              dup(sel,0,2,-3.9327*72,0);
              sel = doc.selection;
              for(var i = 0; i < sel.length; i++)  
              {  
              dup(sel,i,3,0,-3.153*72);
              }
              sel = doc.selection;
              var totalMatrix = app.getScaleMatrix(-100,100);
              for(var j = 0; j <sel.length; j++)  
              {  
              sel[j].transform(totalMatrix);
              }
              function dup(sel,item,qty,tran1,tran2)
              {
              for (var i=0; i<[qty]; i++){  
                sel[item].duplicate();  
                sel[item].translate(tran1,tran2);  
              }  
              }
              
              • 4. Re: duplicating multiple groups?
                mgraphix99 Level 1

                That it does, perfectly actually. Pure genius imagecollection ! Thank you !

                • 5. Re: duplicating multiple groups?
                  Qwertyfly... Level 4

                  Glad I could help.