3 Replies Latest reply on Nov 4, 2017 8:27 AM by perljamz10

    Javascript w/ Illustrator CS5: Simultaneous x, y Object Duplication

    perljamz10

      Hi!

      I am trying to accomplish the duplication of an object so many times across a page, and then that duplicated set down the page.  Unfortunately, only the starting single object gets duplicated and I end up with an upside down L.  I know what I am doing wrong, I just don't know enough to fix it.

       

      I attached the code below.  I found it somewhere else and modified it a bit for my needs.  Somehow I need to group the initially created horizontal array, and then vertically duplicate that group, I'm ignorant on how to do this.  Hopefully someone can help me out.  Maintaining the simplicity and efficiency of the code is key.

       

      if (app.selection[0] != null) {

       

       

        var myDoc = app.activeDocument,

        selectedArt = myDoc.selection[0],

        xclone = 4, // set number of duplicates

               yclone = 6,

        horOffset = 162,  // set horizontal offset

        verOffset = -162,  // set vertical offset

        myDuplicate,

        i = 0

               j = 0

        for (i;i < xclone;i++){

        myDuplicate = selectedArt.duplicate();

        myDuplicate.position = [selectedArt.position[0] + horOffset * (i + 1), selectedArt.position[1] + verOffset * (0)];

        }

         

          for (j;j < yclone;j++){

        myDuplicate = selectedArt.duplicate();

        myDuplicate.position = [selectedArt.position[0] + horOffset * (0), selectedArt.position[1] + verOffset * (j + 1)];

        }

       

       

        }

      else {

        alert("You must have the object you want to duplicate selected.");

        }