6 Replies Latest reply on Jun 1, 2010 9:15 AM by Andreas Jansson

    [CS4 JS] clearTransformations on rotated images - how?

    Andreas Jansson Level 2

      For rectangles and other container objects you can call the clearTransformations() method to remove rotation.

       

      But graphic objects inside such container objects can have a rotations of their own, and I was expecting a clearTransformations mehtod on the graphic object as well, but there doesn't seem to be one.

       

      In InDesign I can select the image (using the Direct Selection Arrow), right click and choose Transform / Clear Transformations.

       

      This can be done on the image container AND on the image. How can I clear the transformations of the graphic objects, from scripting (using javascript).

       

      Best regards,

      Andreas

        • 1. Re: [CS4 JS] clearTransformations on rotated images - how?
          Peter Kahrel Adobe Community Professional & MVP

          Andreas,

           

          Maybe something like this:

           

          myRectangle.clearTranformations();

          myRectangle.graphics[0].clearTranformations();

           

          Peter

          • 2. Re: [CS4 JS] clearTransformations on rotated images - how?
            Andreas Jansson Level 2

            Here is a simple illustration of before (having rotated the container -10 and the contents +10 degrees:

            untitled.PNG

            Then running this code:

             

            var myRectangle = app.selection[0];

            myRectangle = app.selection[0];

            myRectangle.clearTransformations();
            try{
            myRectangle.graphics[0].clearTransformations();
            }catch(e)
            {
            $.writeln(e);   
            }

             

            results in the rectangle being restored to 0, but the rotation "kept" for the inner graphics object (in fact adding 10 degrees to the rotation):

            untitled2.PNG

             

            I've tested that, and that is the only way I can think of to do it... except for resetting the rotation and other transformation properties "manually" by calling, for example, myRectangle.graphics[0].absoluteRotationAngle = 0

             

            Calling clearTransformations for a graphics object results in:

            ReferenceError: myRectangle.graphics[0].clearTransformations is not a function

             

            And looking at the object model in the object browser, searching for all occurrances of clearTransformations, it doesn't appear on any kind of graphic objects. (GraphicLine is the closest match, and I doubt that is useful here.)

             

            I also tried to get the graphics as a pageItem, and run clearTransformations on that, but that resulted in :

            ReferenceError: clearTransformations is undefined

             

            Best regards,

            Andreas

            • 3. Re: [CS4 JS] clearTransformations on rotated images - how?
              Peter Kahrel Adobe Community Professional & MVP

              Turns out that it's images[0], not graphics[0]. This works for me:

               

              myRectangle.clearTransformations();
              myRectangle.images[0].clearTransformations();

               

              though image and rectangle aren't well aligned after clearing the transformations, so the image needs to be moved a bit. A simple "fit image to frame" sorts that out.

               

              Peter

              • 4. Re: [CS4 JS] clearTransformations on rotated images - how?
                Andreas Jansson Level 2

                Peter, this sounded promising... but testing it I still got an error:

                 

                var myRectangle = app.selection[0];
                myRectangle = app.selection[0];
                myRectangle.clearTransformations();
                var myImage = myRectangle.images[0];  // No error here, and the object type of myImage is Image.
                try{
                    myImage.clearTransformations();
                }catch(e)
                {
                $.writeln(e);  
                }

                 

                ReferenceError: myImage.clearTransformations is not a function

                 

                What could differ in our environments?

                Are you running CS4?

                In my object broswer (or using reflect.methods on the image object), I find no clearTransform() method on the image object.

                 

                The script version in my InDeisgn environment is currently 6.0:

                app.scriptPreferences.version
                Result: 6.0

                 

                What image type have you tested with? I've tested with simple jpeg and png images.

                 

                Andreas

                • 5. Re: [CS4 JS] clearTransformations on rotated images - how?
                  Peter Kahrel Adobe Community Professional & MVP

                  Ah! I tried this in CS5. Checking CS4 it is indeed the case that Image doesn't have .clearTransformations(). Tough luck!

                   

                  Peter

                  • 6. Re: [CS4 JS] clearTransformations on rotated images - how?
                    Andreas Jansson Level 2

                    This code resets much of the transformations:

                     

                    var myMatrix = app.transformationMatrices.add({clockwiseRotationAngle:0});
                    myImage.transform(CoordinateSpaces.PASTEBOARD_COORDINATES, AnchorPoint.centerAnchor, myMatrix, 
                       new Array(MatrixContent.rotationValue, MatrixContent.shearValue, 
                                 MatrixContent.scaleValues, MatrixContent.translationValues ));

                     

                    The Array parameter determines the transformations to clear, when a new transformation is added.

                     

                    One visible difference I've discovered yet (compared to selecting the graphics object and right clicking "Transform" / "Clear Transformations") is the location of the object: When there are transformations such as rotation, flip and shear, the graphics object is "displaced" into different locations using my code compared to manually clicking the Clear Transformations in the popup-menu.

                     

                    I guess it has to do with the Coordinate Space and Anchor Points...

                     

                    Andreas