29 Replies Latest reply on May 22, 2016 2:07 AM by c.pfaffenbichler

    Mouse coordinate Or Action?

    守鑫黄40599923

      Dear all:

      I am a new comer in PS scripts. Recently i come across a problem that i want to realize to draw a stable selection as the following picture. QQ图片20160506162049.png

      The ideal situation would be:when i click mouse it may draw a box with script. The rectangle is 50*25 pixels. The sharp one can be missed at first.

      If the ideal situaion cannot be realized, the sharp corner can be placed in the middle of above line, which length is 10.

       

      Now i have two ideas. The first one, when i click in the pic, it may get may mouse coordinates in the info(pressing F8). I want to get the coordinates into memroy, so that scripts can call them to draw a box with selection tool. But i don't know how to get coordinates to memory.

      The second one, when i click the mouse, i can use actions to complete it. But i don't know how to do it.

       

      Thanks all.

        • 1. Re: Mouse coordinate Or Action?
          JJMack Most Valuable Participant

          I do not understand if your drawing interactively with a mouse why would you want to slow the process down trying to script it.  You also can not get the mouse coordinates with scripting and if you could you may be be moveing how would your scriop know when to use the point the mouse is over.

           

          For you all you may need to learn is click move and shift click. straight shart line are easy. You can also use the Pen tool to create a Path then stroke the paths with a tool.

          Capture.jpg

          Custom Shapes work well and can be edited.

          Capture.jpg

          Capture.jpg

          • 2. Re: Mouse coordinate Or Action?
            c.pfaffenbichler Level 9

            Unfortunately I see no current option to collect the mouse position via a Photoshop Script directly.

             

            Work-arounds exist in that

            • the Pen Tool and

            • the Color Sampler Tool for example

            can be used to get the coordinates of a click.

             

            But this is disruptive nonetheless and would not provide for immediate, live interaction per se.

            But again a work-around seems possible if one links the event (of creating a new Color Sampler for example) to a Script with Script Events Manager.

            • 3. Re: Mouse coordinate Or Action?
              守鑫黄40599923 Level 1

              Yeah, i know the pen tool and brush tool. The reason i want to use scripts is that i will create the rectangle with sharp corner many many times, maybe more than several thousand. What is a boring thing. In order to make is easier and intersrting,  i want to use scripts.

              • 4. Re: Mouse coordinate Or Action?
                JJMack Most Valuable Participant

                The rectangle tool will be faster than a Script. A Scripts would be better at rotating and duplicating a rectangle you create using the rectangle tool in pixel mode or shape mode. You have been told that a script can not get the coordinates of the mouse pointer. I use the the color sampler tool to set points for a script to rotate a square rectangle shape I drew.   You can set up to 10 color sampler points.. I set 4.  You could write a script to use two point  the top left and bottom right of a rectangle the script could draw. It would be slower and you would have less control then using Photoshop rectangle tool.

                Capture.jpg

                Rtsqr.gif

                • 5. Re: Mouse coordinate Or Action?
                  守鑫黄40599923 Level 1

                  I get a new idea.

                  • creating a new layer.
                  • creating a anchor with pen tool. (Layer only has an anchor.)
                  • can i select this anchor in the script, then get the coordinate of this anchor? (This step may use script event manager.)
                  • creating an special shape with the coordinate by scripts.

                  Is the idea feasible?

                  • 6. Re: Mouse coordinate Or Action?
                    守鑫黄40599923 Level 1

                    Errrrr, i think i can't let you know what i want to do clearly because of my poor english (I am sorry about this.). I will upload a pic that i do later.

                    • 7. Re: Mouse coordinate Or Action?
                      c.pfaffenbichler Level 9

                      createShapeLayerBasedOnColorSampler.jpg

                      The following code creates a Shape Layer (as seen in the screenshot) based on the last two Color Samplers, the second to last defines the senator of the rectangle, the last one defines one point of a triangle.

                      Naturally you could just as easily use a two point path as the basis, possibly even the Ruler Tool; I just picked Solor Samplers because I seldom use them and so it would – for me – be fairly unproblematic to use them for something different, so to speak.

                      // create shape layer consisting of one rectangle and one triangle based on the last two colorsamplers;

                      // 2016, use it at your own risk;

                      #target photoshop

                      if (app.documents.length > 0) {

                      var myDocument = app.activeDocument;

                      if (myDocument.colorSamplers.length > 1) {

                      // pixels,;

                      var originalRulerUnits = app.preferences.rulerUnits;

                      app.preferences.rulerUnits = Units.PIXELS

                      var originalResolution = myDocument.resolution;

                      myDocument.resizeImage (null, null, 72, ResampleMethod.NONE);

                      var halfWidth = 25;

                      var halfHeight = 12.5;

                      // get coordinates;

                      var theCoord1 = myDocument.colorSamplers[myDocument.colorSamplers.length-2].position;

                      var theCoord2 = myDocument.colorSamplers[myDocument.colorSamplers.length-1].position;

                      // define rectangle;

                      var point1 = [theCoord1[0]-halfWidth,theCoord1[1]-halfHeight];

                      var point2 = [theCoord1[0]+halfWidth,theCoord1[1]-halfHeight];

                      var point3 = [theCoord1[0]+halfWidth,theCoord1[1]+halfHeight];

                      var point4 = [theCoord1[0]-halfWidth,theCoord1[1]+halfHeight];

                      var subPath1 = [[point1, point1, point1, false], [point2, point2, point2, false], [point3, point3, point3, false], [point4, point4, point4, false], true, 1097098272];

                      // define triangle;

                      var distances = [[point1, getDistance(point1, theCoord2)], [point2, getDistance(point2, theCoord2)], [point3, getDistance(point3, theCoord2)], [point4, getDistance(point4, theCoord2)]];

                      distances.sort(sortArrayByIndexedItem);

                      var subPath2 = [[distances[0][0], distances[0][0], distances[0][0], false], [distances[1][0], distances[1][0], distances[1][0], false], [theCoord2, theCoord2, theCoord2, false], true, 1097098272];

                      var theArray = [subPath1, subPath2];

                      // create path;

                      createPath2015(theArray, Math.random());

                      var theShape = solidColorLayer (5, 128, 205);

                      // reset;

                      app.preferences.rulerUnits = originalRulerUnits;

                      myDocument.resizeImage (null, null, originalResolution, ResampleMethod.NONE);

                      };

                      };

                      ////// create a path from collectPathInfoFromDesc2012-array //////

                      function createPath2015(theArray, thePathsName) {

                      var originalRulerUnits = app.preferences.rulerUnits;

                      app.preferences.rulerUnits = Units.POINTS;

                      // thanks to xbytor;

                      cTID = function(s) { return app.charIDToTypeID(s); };

                      sTID = function(s) { return app.stringIDToTypeID(s); };

                       

                       

                          var desc1 = new ActionDescriptor();

                          var ref1 = new ActionReference();

                          ref1.putProperty(cTID('Path'), cTID('WrPt'));

                          desc1.putReference(sTID('null'), ref1);

                          var list1 = new ActionList();

                       

                      for (var m = 0; m < theArray.length; m++) {

                        var thisSubPath = theArray[m];

                       

                          var desc2 = new ActionDescriptor();

                          desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);

                          var list2 = new ActionList();

                          var desc3 = new ActionDescriptor();

                          desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);

                          var list3 = new ActionList();

                       

                      for (var n = 0; n < thisSubPath.length - 2; n++) {

                        var thisPoint = thisSubPath[n];

                       

                          var desc4 = new ActionDescriptor();

                          var desc5 = new ActionDescriptor();

                          desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);

                          desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);

                          desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);

                          var desc6 = new ActionDescriptor();

                          desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);

                          desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);

                          desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);

                          var desc7 = new ActionDescriptor();

                          desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);

                          desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);

                          desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);

                          desc4.putBoolean(cTID('Smoo'), thisPoint[3]);

                          list3.putObject(cTID('Pthp'), desc4);

                       

                        };

                       

                          desc3.putList(cTID('Pts '), list3);

                          list2.putObject(cTID('Sbpl'), desc3);

                          desc2.putList(cTID('SbpL'), list2);

                          list1.putObject(cTID('PaCm'), desc2);

                        };

                       

                          desc1.putList(cTID('T   '), list1);

                          executeAction(cTID('setd'), desc1, DialogModes.NO);

                       

                       

                      // name work path;

                      var check = false;

                      var x = activeDocument.pathItems.length - 1;

                      while (check == false) {

                      if (activeDocument.pathItems[x].kind == PathKind.WORKPATH) {

                      app.activeDocument.pathItems[x].name = thePathsName;

                      var myPathItem = app.activeDocument.pathItems[x];

                      check = true

                      };

                      x--

                      };

                      /*for (var x = 0; x < activeDocument.pathItems.length; x++) {

                        if (activeDocument.pathItems[x].kind == PathKind.WORKPATH) {

                        app.activeDocument.pathItems[x].name = thePathsName;

                        var myPathItem = app.activeDocument.pathItems[x]

                        }

                        };*/

                      app.preferences.rulerUnits = originalRulerUnits;

                      return myPathItem

                      };

                      ////// get a distance between two points //////

                      function getDistance (pointOne, pointTwo) {

                      // calculate the triangle sides;

                        var width = pointTwo[0] - pointOne[0];

                        var height = pointTwo[1] - pointOne[1];

                        var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

                        return sideC

                        };

                      ////// create solid color layer //////

                      function solidColorLayer (theR, theG, theB) {

                      // solid color layer;

                      // =======================================================

                      var idMk = charIDToTypeID( "Mk  " );

                          var desc16 = new ActionDescriptor();

                          var idnull = charIDToTypeID( "null" );

                              var ref4 = new ActionReference();

                              var idcontentLayer = stringIDToTypeID( "contentLayer" );

                              ref4.putClass( idcontentLayer );

                          desc16.putReference( idnull, ref4 );

                          var idUsng = charIDToTypeID( "Usng" );

                              var desc17 = new ActionDescriptor();

                              var idType = charIDToTypeID( "Type" );

                                  var desc18 = new ActionDescriptor();

                                  var idClr = charIDToTypeID( "Clr " );

                                      var desc19 = new ActionDescriptor();

                                      var idRd = charIDToTypeID( "Rd  " );

                                      desc19.putDouble( idRd, theR );

                                      var idGrn = charIDToTypeID( "Grn " );

                                      desc19.putDouble( idGrn, theG );

                                      var idBl = charIDToTypeID( "Bl  " );

                                      desc19.putDouble( idBl, theB );

                                  var idRGBC = charIDToTypeID( "RGBC" );

                                  desc18.putObject( idClr, idRGBC, desc19 );

                              var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

                              desc17.putObject( idType, idsolidColorLayer, desc18 );

                          var idcontentLayer = stringIDToTypeID( "contentLayer" );

                          desc16.putObject( idUsng, idcontentLayer, desc17 );

                      executeAction( idMk, desc16, DialogModes.NO );

                      return activeDocument.activeLayer

                      };

                      ////// sort a double array, thanks to sam, http://www.rhinocerus.net/forum/lang-javascript/ //////

                      function sortArrayByIndexedItem(a,b) {

                      //var theIndex = 1;

                      if (a[1]<b[1]) return -1;

                      if (a[1]>b[1]) return 1;

                      return 0;

                      };

                      • 8. Re: Mouse coordinate Or Action?
                        c.pfaffenbichler Level 9

                        I guess the Count Tool might be even better than Color Sampler or Pen Tool, one could set any number of pairs of points and then have the shapes created based on those in one go.

                        createShapeLayerBasedOnCountToolScr.jpg

                        • 9. Re: Mouse coordinate Or Action?
                          守鑫黄40599923 Level 1

                          wow, how to do this? It may solve my problem probably. Please tell me details about the Count Tool. I never used it before.

                           

                          I cannot run the script with Color Sample Tool (floor 7) successfully. Firstly, open a file.Then, creating a Color Sample? (Please offer some details on this step.)

                           

                          Thanks!

                          • 10. Re: Mouse coordinate Or Action?
                            守鑫黄40599923 Level 1

                            I can successfully run this script with colorsamples, and it can solve my problem absolutely.

                             

                            Thank you cp. Thank you JJMack.

                            Shouxin Huang

                            • 11. Re: Mouse coordinate Or Action?
                              c.pfaffenbichler Level 9

                              You probably already noticed the Script needs two Color Samplers.

                               

                              But I have since noticed that the two nearest points of the rectangle may not be the ideal choice as this could lead to results like this

                              createShapeLayerBasedOnCountToolScr.png

                              It would probably be better to  calculate which side of the rectangle is being cut by a line connecting the two points and use the two points defining that side as the basis for the triangle.

                              • 12. Re: Mouse coordinate Or Action?
                                c.pfaffenbichler Level 9

                                And another thing: You may want to delete the original path after the Shape Layer has been created, otherwise the file might accumulate a lot of useless paths.

                                • 13. Re: Mouse coordinate Or Action?
                                  JJMack Most Valuable Participant

                                  Shape tools ??

                                  Capture.jpg

                                  • 14. Re: Mouse coordinate Or Action?
                                    c.pfaffenbichler Level 9

                                    It may well be an option.

                                    My interpretation of the issue was that the rectangle-element should have a fixed size but the triangle-part may vary.

                                    • 15. Re: Mouse coordinate Or Action?
                                      守鑫黄40599923 Level 1

                                      It is very interesting, how to do that (adding 3 anchors?) in fig.2?

                                      • 16. Re: Mouse coordinate Or Action?
                                        守鑫黄40599923 Level 1

                                        for floor 11:

                                        1.Yeah, i add 2 color samplers in the layer, the script can run successfully and it is so cool.

                                        2.In fact, what i want to do is just like you show, two nearest points are very good.

                                        3.Maybe I can modify the script so that the triangle stay at stable direction in order to fit the entire pic.

                                         

                                        For floor 12:

                                        I agree with you. But my ThinkPad laptop (E530-i3-2G RAM)can only exist 4 color samplers at the same time. I must delete them when there are four points. Why may occur this situation? Maybe my computer is too old? Its cpu only is i3-3110M, and i buy it in 2012.

                                        • 17. Re: Mouse coordinate Or Action?
                                          c.pfaffenbichler Level 9
                                          But my ThinkPad laptop (E530-i3-2G RAM)can only exist 4 color samplers at the same time.

                                          Then you probably use Photoshop CS6 or older.

                                          You could replace the lines

                                          createPath2015(theArray, Math.random());

                                          var theShape = solidColorLayer (5, 128, 205);

                                          with

                                          var aPath = createPath2015(theArray, Math.random());

                                          var theShape = solidColorLayer (5, 128, 205);

                                          aPath.remove();

                                          myDocument.colorSamplers[myDocument.colorSamplers.length-1].remove();

                                          myDocument.colorSamplers[myDocument.colorSamplers.length-1].remove();

                                           

                                          3.Maybe I can modify the script so that the triangle stay at stable direction in order to fit the entire pic.

                                          I don’t understand what you mean exactly, could you provide a screenshot?

                                          • 18. Re: Mouse coordinate Or Action?
                                            c.pfaffenbichler Level 9

                                            If you do not need Color Samplers otherwise you could link the Script to the vvent »Mk  « for the object »ClSm« in Script Events Manager and then it would run whenever a second Color Sampler is created.

                                            • 19. Re: Mouse coordinate Or Action?
                                              c.pfaffenbichler Level 9

                                              Please give this a try:

                                              // create shape layer consisting of one rectangle and one triangle based on the last two colorsamplers;

                                              // 2016, use it at your own risk;

                                              #target photoshop

                                              if (app.documents.length > 0) {

                                              var myDocument = app.activeDocument;

                                              if (myDocument.colorSamplers.length > 1) {

                                              // pixels,;

                                              var originalRulerUnits = app.preferences.rulerUnits;

                                              app.preferences.rulerUnits = Units.PIXELS

                                              var originalResolution = myDocument.resolution;

                                              myDocument.resizeImage (null, null, 72, ResampleMethod.NONE);

                                              var halfWidth = 25;

                                              var halfHeight = 12.5;

                                              // get coordinates;

                                              var theCoord1 = myDocument.colorSamplers[myDocument.colorSamplers.length-2].position;

                                              var theCoord2 = myDocument.colorSamplers[myDocument.colorSamplers.length-1].position;

                                              // define rectangle;

                                              var point1 = [theCoord1[0]-halfWidth,theCoord1[1]-halfHeight];

                                              var point2 = [theCoord1[0]+halfWidth,theCoord1[1]-halfHeight];

                                              var point3 = [theCoord1[0]+halfWidth,theCoord1[1]+halfHeight];

                                              var point4 = [theCoord1[0]-halfWidth,theCoord1[1]+halfHeight];

                                              var subPath1 = [[point1, point1, point1, false], [point2, point2, point2, false], [point3, point3, point3, false], [point4, point4, point4, false], true, 1097098272];

                                              // get angle;

                                              var theAngle = getAngle(theCoord1, theCoord2);

                                              //alert (theAngle);

                                              // define triangle ponts;

                                              switch (true) {

                                              case (theAngle >= 27 && theAngle < 153):

                                              var tr1 = [theCoord1[0]-(halfWidth/3), theCoord1[1]+halfHeight];

                                              var tr2 = [theCoord1[0]+(halfWidth/3), theCoord1[1]+halfHeight];

                                              break;

                                              case (theAngle >= 153 && theAngle < 207):

                                              var tr1 = [theCoord1[0]-halfWidth, theCoord1[1]-(halfHeight/3)];

                                              var tr2 = [theCoord1[0]-halfWidth, theCoord1[1]+(halfHeight/3)];

                                              break;

                                              case (theAngle >= 207 && theAngle < 333):

                                              var tr1 = [theCoord1[0]-(halfWidth/3), theCoord1[1]-halfHeight];

                                              var tr2 = [theCoord1[0]+(halfWidth/3), theCoord1[1]-halfHeight];

                                              break;

                                              default:

                                              var tr1 = [theCoord1[0]+halfWidth, theCoord1[1]-(halfHeight/3)];

                                              var tr2 = [theCoord1[0]+halfWidth, theCoord1[1]+(halfHeight/3)];

                                              break;

                                              };

                                              var subPath2 = [[tr1, tr1, tr1, false], [tr2, tr2, tr2, false], [theCoord2, theCoord2, theCoord2, false], true, 1097098272];

                                              var theArray = [subPath1, subPath2];

                                              // create path;

                                              var aPath = createPath2015(theArray, Math.random());

                                              var theShape = solidColorLayer (5, 128, 205);

                                              aPath.remove();

                                              // remove color samplers;

                                              myDocument.colorSamplers[myDocument.colorSamplers.length-1].remove();

                                              myDocument.colorSamplers[myDocument.colorSamplers.length-1].remove();

                                              // reset;

                                              app.preferences.rulerUnits = originalRulerUnits;

                                              myDocument.resizeImage (null, null, originalResolution, ResampleMethod.NONE);

                                              };

                                              };

                                              ////// create a path from collectPathInfoFromDesc2012-array //////

                                              function createPath2015(theArray, thePathsName) {

                                              var originalRulerUnits = app.preferences.rulerUnits;

                                              app.preferences.rulerUnits = Units.POINTS;

                                              // thanks to xbytor;

                                              cTID = function(s) { return app.charIDToTypeID(s); };

                                              sTID = function(s) { return app.stringIDToTypeID(s); };

                                               

                                               

                                                  var desc1 = new ActionDescriptor();

                                                  var ref1 = new ActionReference();

                                                  ref1.putProperty(cTID('Path'), cTID('WrPt'));

                                                  desc1.putReference(sTID('null'), ref1);

                                                  var list1 = new ActionList();

                                               

                                              for (var m = 0; m < theArray.length; m++) {

                                                var thisSubPath = theArray[m];

                                               

                                                  var desc2 = new ActionDescriptor();

                                                  desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);

                                                  var list2 = new ActionList();

                                                  var desc3 = new ActionDescriptor();

                                                  desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);

                                                  var list3 = new ActionList();

                                               

                                              for (var n = 0; n < thisSubPath.length - 2; n++) {

                                                var thisPoint = thisSubPath[n];

                                               

                                                  var desc4 = new ActionDescriptor();

                                                  var desc5 = new ActionDescriptor();

                                                  desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);

                                                  desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);

                                                  desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);

                                                  var desc6 = new ActionDescriptor();

                                                  desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);

                                                  desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);

                                                  desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);

                                                  var desc7 = new ActionDescriptor();

                                                  desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);

                                                  desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);

                                                  desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);

                                                  desc4.putBoolean(cTID('Smoo'), thisPoint[3]);

                                                  list3.putObject(cTID('Pthp'), desc4);

                                               

                                                };

                                               

                                                  desc3.putList(cTID('Pts '), list3);

                                                  list2.putObject(cTID('Sbpl'), desc3);

                                                  desc2.putList(cTID('SbpL'), list2);

                                                  list1.putObject(cTID('PaCm'), desc2);

                                                };

                                               

                                                  desc1.putList(cTID('T   '), list1);

                                                  executeAction(cTID('setd'), desc1, DialogModes.NO);

                                               

                                               

                                              // name work path;

                                              var check = false;

                                              var x = activeDocument.pathItems.length - 1;

                                              while (check == false) {

                                              if (activeDocument.pathItems[x].kind == PathKind.WORKPATH) {

                                              app.activeDocument.pathItems[x].name = thePathsName;

                                              var myPathItem = app.activeDocument.pathItems[x];

                                              check = true

                                              };

                                              x--

                                              };

                                              /*for (var x = 0; x < activeDocument.pathItems.length; x++) {

                                                if (activeDocument.pathItems[x].kind == PathKind.WORKPATH) {

                                                app.activeDocument.pathItems[x].name = thePathsName;

                                                var myPathItem = app.activeDocument.pathItems[x]

                                                }

                                                };*/

                                              app.preferences.rulerUnits = originalRulerUnits;

                                              return myPathItem

                                              };

                                              ////// get a distance between two points //////

                                              function getDistance (pointOne, pointTwo) {

                                              // calculate the triangle sides;

                                                var width = pointTwo[0] - pointOne[0];

                                                var height = pointTwo[1] - pointOne[1];

                                                var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

                                                return sideC

                                                };

                                              ////// get an angle, 3:00 being 0˚, 6:00 90˚, etc. //////

                                              function getAngle (pointOne, pointTwo) {

                                              // calculate the triangle sides;

                                                var width = pointTwo[0] - pointOne[0];

                                                var height = pointTwo[1] - pointOne[1];

                                                var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

                                              // calculate the angles;

                                                if (width+width > width) {theAngle = Math.asin(height / sideC) * 360 / 2 / Math.PI}

                                                else {theAngle = 180 - (Math.asin(height / sideC) * 360 / 2 / Math.PI)};

                                                if (theAngle < 0) {theAngle = (360 + theAngle)};

                                              // if (theAngle > 180) {theAngle = (360 - theAngle) * (-1)};

                                                return theAngle

                                                };

                                              ////// create solid color layer //////

                                              function solidColorLayer (theR, theG, theB) {

                                              // solid color layer;

                                              // =======================================================

                                              var idMk = charIDToTypeID( "Mk  " );

                                                  var desc16 = new ActionDescriptor();

                                                  var idnull = charIDToTypeID( "null" );

                                                      var ref4 = new ActionReference();

                                                      var idcontentLayer = stringIDToTypeID( "contentLayer" );

                                                      ref4.putClass( idcontentLayer );

                                                  desc16.putReference( idnull, ref4 );

                                                  var idUsng = charIDToTypeID( "Usng" );

                                                      var desc17 = new ActionDescriptor();

                                                      var idType = charIDToTypeID( "Type" );

                                                          var desc18 = new ActionDescriptor();

                                                          var idClr = charIDToTypeID( "Clr " );

                                                              var desc19 = new ActionDescriptor();

                                                              var idRd = charIDToTypeID( "Rd  " );

                                                              desc19.putDouble( idRd, theR );

                                                              var idGrn = charIDToTypeID( "Grn " );

                                                              desc19.putDouble( idGrn, theG );

                                                              var idBl = charIDToTypeID( "Bl  " );

                                                              desc19.putDouble( idBl, theB );

                                                          var idRGBC = charIDToTypeID( "RGBC" );

                                                          desc18.putObject( idClr, idRGBC, desc19 );

                                                      var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

                                                      desc17.putObject( idType, idsolidColorLayer, desc18 );

                                                  var idcontentLayer = stringIDToTypeID( "contentLayer" );

                                                  desc16.putObject( idUsng, idcontentLayer, desc17 );

                                              executeAction( idMk, desc16, DialogModes.NO );

                                              return activeDocument.activeLayer

                                              };

                                              ////// sort a double array, thanks to sam, http://www.rhinocerus.net/forum/lang-javascript/ //////

                                              function sortArrayByIndexedItem(a,b) {

                                              //var theIndex = 1;

                                              if (a[1]<b[1]) return -1;

                                              if (a[1]>b[1]) return 1;

                                              return 0;

                                              };

                                              • 20. Re: Mouse coordinate Or Action?
                                                JJMack Most Valuable Participant

                                                You use Photoshop Vector graphic tools. Rectangle Tool in shape mode  stroke shape no fill.

                                                Capture.jpg

                                                 

                                                Pen Tool + add anchor points tool to add three points these will have handles you do not want.

                                                Capture.jpg.

                                                 

                                                You use the Convert Point Tool to remove the handle from the three you added.

                                                Capture.jpg

                                                 

                                                You use the direct selection tool to select the center point then use the tool to drag it to where you want it.

                                                Capture.jpg

                                                Adding  one point convert and move.

                                                Capture.jpg

                                                • 21. Re: Mouse coordinate Or Action?
                                                  守鑫黄40599923 Level 1

                                                  Thanks JJMack.

                                                  I cannot do it successfully because i don't know how to remove the anchor's handle. The important tool is Convert Point Tool, and i click on the anchor with Convert Point Tool, the handle disappears.

                                                  This idea is very useful for me in other work.

                                                  • 22. Re: Mouse coordinate Or Action?
                                                    JJMack Most Valuable Participant

                                                    守鑫黄40599923 wrote:

                                                     

                                                    Thanks JJMack.

                                                    I cannot do it successfully because i don't know how to remove the anchor's handle. The important tool is Convert Point Tool, and i click on the anchor with Convert Point Tool, the handle disappears.

                                                    This idea is very useful for me in other work.

                                                    That is correct you have removed the handle with the convert tool. Now the control point are points controls  for straight  angled lines no curves when you move the center point the connecting lines will be straight lines with no curves just straight lines with sharp angles.

                                                    • 23. Re: Mouse coordinate Or Action?
                                                      c.pfaffenbichler Level 9

                                                      With the last version of the Script linked to the event via Script Events Manager one can create Shape Layers pretty easily.

                                                      colorSamplerShapeLayers.gif

                                                      • 24. Re: Mouse coordinate Or Action?
                                                        守鑫黄40599923 Level 1

                                                        yeah, i can do the same thing with you. The script is very good for me.

                                                        • 25. Re: Mouse coordinate Or Action?
                                                          守鑫黄40599923 Level 1

                                                          I come across a new problem as following.

                                                          Untitled-1.jpg

                                                          I notice the circle is created by 4 points, but i don't how to create path to a circle. The other part is also a triangle. I can solve the little triangle by myself.

                                                          Thanks all.

                                                          • 26. Re: Mouse coordinate Or Action?
                                                            c.pfaffenbichler Level 9

                                                            Roughly like this (I am not good at triangulation so I tried getting the value from a circular Path I created with the Ellipse Tool):

                                                            // 2016, use it at your own risk;

                                                            #target photoshop

                                                            if (app.documents.length > 0) {

                                                            var myDocument = app.activeDocument;

                                                            if (myDocument.colorSamplers.length > 1) {

                                                            // pixels,;

                                                            var originalRulerUnits = app.preferences.rulerUnits;

                                                            app.preferences.rulerUnits = Units.PIXELS

                                                            var originalResolution = myDocument.resolution;

                                                            myDocument.resizeImage (null, null, 72, ResampleMethod.NONE);

                                                            var halfWidth = 25;

                                                            var halfHeight = 25;

                                                            var theBezierHandle = 0.55226734110625;

                                                            var bezierHor = halfWidth*theBezierHandle;

                                                            var bezierVert = halfHeight*theBezierHandle;

                                                            // get coordinates;

                                                            var theCoord1 = myDocument.colorSamplers[myDocument.colorSamplers.length-2].position;

                                                            var theCoord2 = myDocument.colorSamplers[myDocument.colorSamplers.length-1].position;

                                                            // define rectangle;

                                                            var point1 = [theCoord1[0]-halfWidth,theCoord1[1]];

                                                            var point2 = [theCoord1[0],theCoord1[1]-halfHeight];

                                                            var point3 = [theCoord1[0]+halfWidth,theCoord1[1]];

                                                            var point4 = [theCoord1[0],theCoord1[1]+halfHeight];

                                                            var subPath1 = [[point1, [point1[0],theCoord1[1]-bezierVert], [point1[0],theCoord1[1]+bezierVert], false],

                                                            [point2, [theCoord1[0]+bezierHor,point2[1]], [theCoord1[0]-bezierHor,point2[1]], false],

                                                            [point3, [point3[0],theCoord1[1]+bezierVert], [point3[0],theCoord1[1]-bezierVert], false],

                                                            [point4, [theCoord1[0]-bezierHor,point4[1]], [theCoord1[0]+bezierHor,point4[1]], false], true, 1097098272];

                                                            etc.

                                                            • 27. Re: Mouse coordinate Or Action?
                                                              c.pfaffenbichler Level 9

                                                              Did you ultimately use Script Events Manager to automatically trigger the Script when you set Color Samplers?

                                                               

                                                              Also you may want to start a new thread when you have additional questions, that way you might attract additional attention and someone else might chime in and possibly offer a different/better approach.

                                                              • 28. Re: Mouse coordinate Or Action?
                                                                守鑫黄40599923 Level 1

                                                                Thanks c.p very much. Your code solves my promblem perfectly which can draw a circle.

                                                                But I can't understand well about your rule or path, could you give me a description of path array, or explanation?

                                                                • 29. Re: Mouse coordinate Or Action?
                                                                  c.pfaffenbichler Level 9

                                                                  The Array I use in a function to create a path is as follows (well, hopefully I can make it halfway clear):

                                                                   

                                                                  • Array contains

                                                                       • one Array for each subPathItem which contains

                                                                            • Arrays of Arrays for the points

                                                                                 • the point (expressed as an Array of two numbers)

                                                                                 • forward bezier handle (expressed as an Array of two numbers)

                                                                                 • backward bezier handles (expressed as an Array of two numbers)

                                                                                 • smooth or not

                                                                            • closed or not

                                                                            • shape operation

                                                                   

                                                                  So something like:

                                                                  [

                                                                  [

                                                                  [[293.130859375,160.04296875],[335.737674639453,160.04296875],[250.524044110547,160.042968 75],true],

                                                                  [[370.27734375,237.189453125],[370.27734375,279.796268389453],[370.27734375,194.5826378605 47],true],

                                                                  [[293.130859375,314.3359375],[250.524044110547,314.3359375],[335.737674639453,314.3359375] ,true],

                                                                  [[215.984375,237.189453125],[215.984375,194.582637860547],[215.984375,279.796268389453],tr ue],

                                                                  true,

                                                                  1097098272

                                                                  ]

                                                                  ]