4 Replies Latest reply on Jan 28, 2011 1:18 PM by Gonterman1201

    Get values for Measure Tool

    Gonterman1201 Level 1

      I am interested in getting the values from the measure tool. These appear in the info pallet. Specifically I am looking for the angle info. I can find Info and Measure tool through the menuAction but i can not find any properties for them. If this is possible I would like to know how to acess this.

        • 1. Re: Get values for Measure Tool
          Gonterman1201 Level 1

          I have looked around and I have been unable to find a possible way to access the info for Measure Tool. So I tried this.

           

           

          var myInfoDialog = app.dialogs.add({name:"Alignment", canCancel:true});
              with(myInfoDialog){
              //Add a dialog column.
              with(dialogColumns.add()){
                  //Create a border panel.
                  with(borderPanels.add()){
                      with(dialogColumns.add()){
                          //The following line shows how to set a property as you create an object.
                          staticTexts.add({staticLabel:"Please Choose Verticalor Horizontal  Alignment     "});
                      }
                  with(dialogColumns.add()){
                  //Create a border panel.
                  with(borderPanels.add()){
                  var myOrient = radiobuttonGroups.add();    
              with(myOrient){
                  radiobuttonControls.add({staticLabel:"Vertical", checkedState: true});
              radiobuttonControls.add({staticLabel:"Horizontal", checkedState: false});
              }
          }
                      }
                  }
              }
          }
          var myResult = myInfoDialog.show();
          if(myResult == true){
              if(myOrient.selectedButton ==1){
                  var myAlignment=0;
                  }
              else{
                  var myAlignment=90;
                  }
          findAngle();
          }
          function findAngle(){
              myPath=app.selection[0];
             var lineStart = myPath.paths.item(0).pathPoints.item(0).anchor;
             var lineEnd = myPath.paths.item(0).pathPoints.item(-1).anchor;
             var a = Math.abs(lineStart[0]-lineEnd[0]);
             var o = Math.abs(lineStart[1]-lineEnd[1]);
              c = (180/Math.PI) * Math.atan2(o,a);
              c=c-myAlignment
             if(lineStart[0] < lineEnd[1]){
                c = -c;
             };
             var myRotateMatrix = app.transformationMatrices.add({counterclockwiseRotationAngle:c});
             myPath.transform(CoordinateSpaces.pasteboardCoordinates, AnchorPoint.CENTER_ANCHOR, myRotateMatrix);
             dSelect=app.selection=NothingEnum.NOTHING;
            
          };

           

           

          Unfortunatley it only works on the first rotation. For some reason on subsiquint rotations it fails to return to a 90 degree angle.

          Any help with this would be great.

          • 2. Re: Get values for Measure Tool
            [Jongware]-9BC6tI Level 4

            The property "rotationAngle" doesn't do what you need?

             

            It also depends on the type of object you are trying to measure. This simple four-point object

             

            Screen shot 2011-01-28 at 9.24.21 PM.png

             

            is not rotated -- but your code would say it is.

            • 3. Re: Get values for Measure Tool
              Gonterman1201 Level 1

              If i create a rectangle and rotate it. The script works the first time. If i hit it again and choose either horizontal or vertical it rotates but not back to 90 degrees. I am wondering if the point of rotation is changing?

              • 4. Re: Get values for Measure Tool
                Gonterman1201 Level 1

                My hope is to get results similar to using the measure tool in Photoshop to get an arbitrary rotation.