4 Replies Latest reply on Jan 29, 2016 7:41 AM by CarlosCanto

    Set all layer coordinates in a document

    venko

      Hi all,

       

      I have an ordered list of layers (ordered by name) in the layers window. However those layers are not ordered on the canvas, so I would like to order them. I thought it would be pretty easy task but Illustrator just doesn't return/set the proper coordinates. Maybe I reference the wrong elements.
      The structure of a layer itself is something like this:
      Layer

      ---Text
      ---Group

      ------Group <-- here are the shapes

       

      So I basically try to move each group item by step of 24px, see below:

       

      var doc = app.documents[0]; 

      var lay = doc.layers; 

      var array_primary = []; 

       

      for(var k = 0; k < lay.length; k++) {

              lay[k].groupItems[0].top = k*24;

              lay[k].groupItems[1].top = k*24;

      }

      BTW I use Illustrator CS6 and CC.

       

      Could you please give me a hand on this, thanks!

        • 1. Re: Set all layer coordinates in a document
          Silly-V Adobe Community Professional

          Can you try

           

          for(var k = 0; k < lay.length; k++) {

                  lay[k].groupItems[0].top = (lay[k].groupItems[0].top - 24);

                  lay[k].groupItems[1].top = (lay[k].groupItems[0].top - 24);

          }

          • 2. Re: Set all layer coordinates in a document
            venko Level 1

            Hi,

            Thanks for the response.

             

            The proposed code simply translates all icons by 24px. What I try to do is to reorder them. I use the fact that they are already ordered in the layer window (by another script), so I know that itme 0 in this list should correspont to Y = 0x24px = 0 on the canvas, item 1 to Y = 1x24px = 24px, item 2 to Y = 2x24px = 48px and so on. The thing is that I don't think this api is the proper one, i.e. .top/.left. They return some strange values. For instance the top item on the canvas doesn't have top = 0 in the same manner as if I set top = 0 to a layer it doesn't move to top = 0 on the canvas, but somewhere in the middle.

             

            Attached is an image how the document looks like.layers.png

            • 3. Re: Set all layer coordinates in a document
              venko Level 1

              Could someone share his thoughts on this? I'll appreciate it much.

              • 4. Re: Set all layer coordinates in a document
                CarlosCanto Adobe Community Professional & MVP

                try changing your rulers settings to "Global Rulers" and drag and drop your (0, 0) where you want your first group to be.

                 

                or to make it more reliable, calculate the coordinates (relative to the Artboard left/top) of the (x, y) where you want your first group to be, then move all your groups relative to this point.