2 Replies Latest reply on Aug 13, 2013 7:09 PM by mr.stuckUp

    selection coordinates output

    mr.stuckUp Level 1

      Good day to all,

       

      First of all, I am so new in programming.

      I just learn about a week (Java Language).

       

      I already have a code that shows the coordinates of selected area.

      But the output in the text file is x,y,x,y,x,y...

      I want the output to be x,x,x... and y,y,y... in new line.

       

      Example:

       

      In the code, the output is:

       

      578,337,529,488,512,526,478,512,486,464,484,464,480,475,477,475,479,458,477,458,472,462,47 2,458,476,442,484,420,519,363,528,355,554,334

       

      What I want is:

       

      578,529,512,489,478,486,484,480,477,479,477,472,472,476,484,519,528,554

      337,488,526,517,512,464,464,475,475,458,458,462,458,442,420,363,355,334

       

      I mean the x coordinates are on first line and y are on the second line.

       

      Here is my code:

       

      #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('~/Desktop/coords.txt');

      fileOut.linefeed = fileLineFeed;

      fileOut.open("w", "TEXT", "");

      fileOut.writeln(data.mapa[0]);

      fileOut.close();

       

      Thanks to muyshangai for the codes.

       

       

      And thank you guys in advance

        • 1. Re: selection coordinates output
          Michael L Hale Level 5
          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
          }
          // data,mapa is an array of nested arrays
          alert(data.mapa.toSource());
          // here is how to 'split' the x,y array of the first subPath
          var xArray = [];
          var yArray = [];
          for(var i=0;i<data.mapa[0].length;i++){
              xArray.push(data.mapa[0][i][0]);
              yArray.push(data.mapa[0][i][1]);
          }
          //data.mapa[0];
          
          if ($.os.search(/windows/i) != -1){
              fileLineFeed = "windows";
          }else{
              fileLineFeed = "macintosh";
          }
          var fileName = app.activeDocument.name
          
          var fileOut = new File('~/Desktop/coords.txt');
          fileOut.linefeed = fileLineFeed;
          fileOut.open("w", "TEXT", "");
          //fileOut.writeln(data.mapa[0]);
          fileOut.writeln(xArray);
          fileOut.writeln(yArray);
          fileOut.close();
          
          • 2. Re: selection coordinates output
            mr.stuckUp Level 1

            Thank you so much sir