2 Replies Latest reply on Mar 11, 2010 7:15 AM by SteeleRBG

    Detailed selection coordinates

    SteeleRBG

      First, thanks to muyshangai I've got the script to get the coords of the selected area:

       

       

      #target Photoshop

       

      var data=mapa_seleccion(activeDocument,data)

       

      function mapa_seleccion(doc,out){
            var hs = doc.historyStates;
            preferences.rulerUnits = Units.PIXELS;
            doc.selection.makeWorkPath(1);
            var p = doc.pathItems["Work Path"];
            var a = new Array();
            var t = 0;
            var l = p.subPathItems.length;
            for ( k = 0; k < l; k++) {
                 var n = p.subPathItems[k].pathPoints.length;
                 a[k] = new Array (n);
                 for ( i = 0; i < n; i++){
                      a[k][i] = new Array();
                      a[k][i]=p.subPathItems[k].pathPoints[i].anchor;
                      }
                 }
            var t = 0;
            for ( k = 0; k < l; k++) {
                 var n = a[k].length;
                 var s = 0;
                 for ( i = 0; i < n; i++){
                      var j = (i+1)%n;
                      s+=(a[k][i][0]*a[k][j][1]);
                      s-=(a[k][i][1]*a[k][j][0]);
                      }
                 s/=2;
                 t+=s;

       

                 }

       

            doc.activeHistoryState = hs[hs.length-2];
            out=new Array()
            out.mapa=a
            out.area=parseFloat(t/doc.resolution/doc.resolution*2.54*2.54).toFixed(2)//conv ierte a cm2

       

            return out
            }

       

      alert(data.mapa[0]);

       

      //data.mapa[0];
      if ($.os.search(/windows/i) != -1)
          fileLineFeed = "windows";
      else
          fileLineFeed = "macintosh";
         
      var fileName = app.activeDocument.name

       

      var fileOut = new File('/c/coords.txt');
      fileOut.linefeed = fileLineFeed;
      fileOut.open("w", "TEXT", "");
      fileOut.writeln(data.mapa[0]);
      fileOut.close();

       

       

       

      However, it turned out that the coordinates it gets are only describing the selected area. I.e.:

      this is the selected area:

      select-area.png

      this is the resulted coords:

      result.png


      can anyone help me figure out how to get more exact coords ?

       

      Thanks