4 Replies Latest reply on Oct 18, 2016 8:53 AM by Silly-V

    Rotate around a custom pivot???

    Heimdaal Level 1

      I want to rotate an element around a custom pivot, however according to the manual there doesn't seem to be a way of setting a custom one (parameter is an enumeration with pre-defined keywords).

       

      myElement.rotate(angle, 0, 0, 0, 0, Transformation.DOCUMENTORIGIN);

       

      The sixth parameter can have the following:

      Transformation.BOTTOM

      Transformation.BOTTOMLEFT

      Transformation.BOTTOMRIGHT

      Transformation.CENTER

      Transformation.DOCUMENTORIGIN

      Transformation.LEFT

      Transformation.RIGHT

      Transformation.TOP

      Transformation.TOPLEFT
      Transformation.TOPRIGHT

       

      How do I proceed with this? I know the coordinates of the point I want to rotate around.

       

      EDIT
      I've also tried:
      var myMatrix = new Matrix(0,0,0,0,myPivotX, myPivotY); // Where myPivotX and myPivotY are floats representing the pivot point on the canvas (pt)
      ...and passing that as the argument to the rotate function. That only results in the error:

      Illegal argument - argument 6

        • 1. Re: Rotate around a custom pivot???
          Silly-V Adobe Community Professional

          You can do an awesome trick my setting the document ruler origin to a custom point (after saving original one in memory for safety) and using the first line you mention there. This should rotate it alright, and then you can set the ruler origin back!

          1 person found this helpful
          • 2. Re: Rotate around a custom pivot???
            Heimdaal Level 1

            I'm impressed! That's a very hacky but solid solution - you think like a Technical Artist

            • 3. Re: Rotate around a custom pivot???
              Silly-V Adobe Community Professional

              I also tried to test it out and it's not as straight-forward, the ruler origin seems to be at the bottom left corner for scripting purposes while the UI is not the same. So you have to do additional stuff to make it good.

               

              #target illustrator
              function test(){
              
              
                  function marker(xy){
                      var x =xy[0];
                      var y = xy[1];
                      var doc=app.activeDocument;
                      var lr = doc.activeLayer;
                      lr.visible = true;
                      lr.locked = false;
                      var m = lr.pathItems.ellipse(y-3, x-3, 6, 6);
                      m.stroked = false;
                      m.filled = true;
                  }
              
                var doc = app.activeDocument;
              
              
                var originalOrigin = doc.rulerOrigin;
                var angle = 45;
                var pivot = doc.pathItems.getByName("pivot");
              //~  marker([pivot.left + (pivot.width/2), pivot.top + (pivot.height/2)]); return; // puts the marker where the pivot is, but the ruler Origin is messed up.
                doc.rulerOrigin = [pivot.left + (pivot.width/2), doc.height + (pivot.top - (pivot.height/2))]; // ruler origin works when combined with the document height. My scripting ruler origin is by default at bottom left corner as opposed to top left.
              
              
                var item = doc.pathItems.getByName("thing");
                for(var i=0; i<8; i++){
                  doc.pageItems[doc.pageItems.length - 1].duplicate(doc.pageItems[doc.pageItems.length - 1], ElementPlacement.PLACEAFTER).rotate(angle, true, true, true, true, Transformation.DOCUMENTORIGIN);
                };
              
                doc.rulerOrigin = originalOrigin;
              
                marker(doc.rulerOrigin);
              
              };
              test();
              

               

              My Document set up:

              2016-10-18 10_24_55-.png

              What happens when the ruler origin is not edited using the doc height in the calculation:
              (the orange circle rotation point is supposed to be where the red pivot is!)
              2016-10-18 10_19_28-Untitled-3_ @ 300% (RGB_Preview).png

               

              Corrected:

              2016-10-18 10_24_44-Untitled-3_ @ 300% (RGB_Preview).png

              1 person found this helpful
              • 4. Re: Rotate around a custom pivot???
                Silly-V Adobe Community Professional

                It may seem hacky - but compared to some other things in AI scripting, this is totally legit!

                One MOST useful thing about changing the doc origin to perform these transforms (scale, rotate..) is that you can transform multiple items without having to have them grouped or selected!