10 Replies Latest reply on Jan 9, 2017 7:25 AM by Silly-V

    How to get the angle of an object ?

    tt27079448 Level 1

      How to get the angle of an object ?

      234.png

        • 1. Re: How to get the angle of an object ?
          moluapple Level 4

          For objects which have "matrix" property(images, textframes), the math can be:

          var matrix = app.selection[0].matrix;
          alert(180/Math.PI * Math.atan2(matrix.mValueC, matrix.mValueD));  
          
          3 people found this helpful
          • 2. Re: How to get the angle of an object ?
            Silly-V Adobe Community Professional

            If you are dealing with most types of art , you can check to see if the automatically-added "BBAccumRotation" tag is at work. This 'tag' is a scripting object that's not accessible from the UI, and likely serves some sort of Illustrator purpose. It is automatically added to art items when the rotation tools are used within AI to rotate them.

             

            #target illustrator

            function test(){

                var doc = app.activeDocument;

                var sel = doc.selection[0];

                if(sel.tags.length > 0 && sel.tags[0].name == "BBAccumRotation"){

                  alert(sel.tags[0].value); //in radians

                }

            };

            test();

            2 people found this helpful
            • 3. Re: How to get the angle of an object ?
              tt27079448 Level 1

              thanks very much

              • 4. Re: How to get the angle of an object ?
                tt27079448 Level 1

                thanks very much

                 

                function test(){

                    var doc = app.activeDocument;

                    var sel = doc.selection[0];

                    if(sel.tags.length > 0 && sel.tags[0].name == "BBAccumRotation"){

                      alert("Angle : "+180 *sel.tags[0].value/Math.PI); //in radians

                    }

                };

                test();

                • 5. Re: How to get the angle of an object ?
                  tt27079448 Level 1

                  How to judge a object have  been a mirrored?

                  • 6. Re: How to get the angle of an object ?
                    Silly-V Adobe Community Professional

                    I tried this same code with an object which was reflected over an axis using the Mirror tool (O), and this tag was still added (with no rotation tool used) and the value is negative Pi: -3.141593

                    • 8. Re: How to get the angle of an object ?
                      Silly-V Adobe Community Professional

                      Yes it makes no sense, and I would definitely go the matrix way as moluapple

                      • 9. Re: How to get the angle of an object ?
                        tt27079448 Level 1

                        /////////how to rotate or mirror the image????

                         

                         

                        ASSET_FOLDER_NAME = "links";

                        doc = app.activeDocument;

                        var filename = doc.name.split(".")[0];

                         

                         

                        asset_folder = new Folder(doc.path + "/" + ASSET_FOLDER_NAME);

                         

                         

                        if (asset_folder.exists || asset_folder.create()) {

                            for (i =doc.placedItems.length-1;  i >-1; i--) {

                                linked_file = doc.placedItems[i].file;

                                collected_file = new File(asset_folder + "/" + linked_file.name);

                                if (collected_file.fullName != linked_file.fullName) {

                                    linked_file.copy(collected_file);

                                    doc.placedItems[i].file = collected_file;

                                }

                            }

                         

                         

                            for (i = doc.rasterItems.length-1; i >-1; i--) {

                                if (doc.rasterItems[i].embedded) {

                                     relink_image(doc.rasterItems[i]);

                                }

                            }

                         

                         

                        } else {

                            alert("Unable to create the assets folder.");

                        }

                         

                         

                         

                         

                        function relink_image(myFile){

                            try{

                                linked_file = myFile.file ;

                                tempFpath = new File(asset_folder + "/" + linked_file.name);

                                 if (tempFpath.fullName != linked_file.fullName)

                                 linked_file.copy(tempFpath);

                                }

                            catch(err){

                                    var myBBox = myFile.boundingBox;

                                    var myBounds = myFile.geometricBounds;

                                    var tempFpath = newFileName();

                                    var newDocu = app.documents.add();

                                    var newobj = myFile.duplicate(newDocu);

                                    newobj. position = Array(0,0);

                                    if(myBounds[2]-myBounds[0] > myBounds[1]-myBounds[3]){

                         

                         

                                        if(myBBox[2] > myBBox[1]){

                         

                         

                                            newobj.width = myBBox[2]-0.1;

                                            newobj.height = myBBox[1]-0.1;

                                        }else{

                                            newobj.height = myBBox[2]-0.1;

                                            newobj.width = myBBox[1]-0.1;

                                        }

                                    }else{

                         

                         

                                        if(myBBox[2] > myBBox[1]){

                         

                         

                                            newobj.height = myBBox[2]-0.1;

                                            newobj.width = myBBox[1]-0.1;

                                        }else{

                                            newobj.width = myBBox[2]-0.1;

                                            newobj.height = myBBox[1]-0.1;

                                        }

                                    }

                                    var exportPSDOptions = new ExportOptionsPhotoshop();

                                    exportPSDOptions.resolution = 72;

                                    exportPSDOptions.imageColorSpace = ImageColorSpace.CMYK;//gray:1,RGB:2,CMYK:3

                                    newDocu.exportFile (tempFpath , ExportType.PHOTOSHOP,exportPSDOptions);

                                    newDocu.close(SaveOptions.DONOTSAVECHANGES);

                            }

                          var replacedImage = doc.placedItems.add();

                          replacedImage.file = tempFpath;

                          replacedImage.position = myFile.position;

                          replacedImage.width = myFile.width;

                          replacedImage.height = myFile.height;

                          replacedImage.move(myFile,ElementPlacement.PLACEAFTER);

                            //how to rotate or mirror the image????

                          

                          

                          myFile.remove();

                        }

                        function newFileName(){

                          var N = 1;

                          var loopFlg = true;

                          while(loopFlg){

                          var fileObj = new File(asset_folder+"/"+filename+"-"+N+".psd");

                          N++;

                          if(! fileObj.exists){

                          loopFlg = false;

                          return fileObj;

                          }

                          }

                        }

                        • 10. Re: How to get the angle of an object ?
                          Silly-V Adobe Community Professional

                          Use the .resize and .rotate to rotate, scale and mirror the object. Using a negative value for the scaleX or scaleY will flip the object over that axis.