2 Replies Latest reply on Sep 23, 2012 1:39 PM by uplink777

    Copy and Paste position and size of two different objects

    uplink777

      Salutations,

       

      I was moved from main topic in here, a guy named Mylenium suggested I should try it here, so here I am

       

      I have a question, quite a tricky one. Is there any way how can I copy and paste position and size of two objects?

       

      Let's say I have a circle 2 x 2 cm and it's position is y 5cm x 5cm, I have a square of size 3 x 7 cm and it's position is y 0cm x 0cm.

       

      How do I copy and paste in a single command/step the circles position and size to square, so I can get square of 2 x 2 cm and it's position 5cm x 5cm?

       

      Something like copy + paste in place with a different logics. I hope You understand what I want.

       

      I'm doing it now manually, I'm copying size and position of one object to another [ctrl + c > ctrl + v] but it takes quiet a while,

       

      Thank You for any suggestions,

       

      regards

       

      Bryan

        • 1. Re: Copy and Paste position and size of two different objects
          pixxxel schubser Level 5

          without copy&paste

           

          try this:

           

          //swap2objects
          
          var myDoc = app.activeDocument;
          if (myDoc.selection.length == 2) {
              //alert (myDoc.selection.length)
              var obj1 = myDoc.selection[0];
              var obj1Bounds = obj1.geometricBounds;
              var obj1_Li = obj1Bounds[0];
              var obj1_Ob = obj1Bounds[1];
              var obj1_Re = obj1Bounds[2];
              var obj1_Un = obj1Bounds[3];
              var obj1XCenter = (obj1_Re - obj1_Li)/2 + obj1_Li;
              var obj1YCenter = (obj1_Ob - obj1_Un)/2 + obj1_Un;
              
              var obj2 = myDoc.selection[1];
              var obj2Bounds = obj2.geometricBounds;
              var obj2_Li = obj2Bounds[0];
              var obj2_Ob = obj2Bounds[1];
              var obj2_Re = obj2Bounds[2];
              var obj2_Un = obj2Bounds[3];
              var obj2XCenter = (obj2_Re - obj2_Li)/2 + obj2_Li;
              var obj2YCenter = (obj2_Ob - obj2_Un)/2 + obj2_Un;
              
              var obj1moveX = obj2XCenter - obj1XCenter;
              var obj1moveY = obj2YCenter - obj1YCenter;
              
              var obj2moveX = obj1XCenter - obj2XCenter;
              var obj2moveY = obj1YCenter - obj2YCenter;
              
              obj1.translate (obj1moveX,obj1moveY);
              obj2.translate (obj2moveX,obj2moveY);
              app.redraw();
              
              } else {
                  alert ("Bitte genau 2 Objekte markieren")
                  }
          

           

          Open a new document, draw 2 objects and run the script. (only tested with Ai CS3)

           

          Good Luck

          • 2. Re: Copy and Paste position and size of two different objects
            uplink777 Level 1

            Thank You for Your time and effort! I'll try it as soon as I'm back in Illustrator. I'm stuck with rasters for a few days for now [Photoshop]. Thank You one more time

            pixxxel schubser.