13 Replies Latest reply on Jul 3, 2018 2:13 AM by Laubender

    How to get PathPointInfo or SubPathInfo?

    bestwave

      I am trying to modify a work path.

       

      These statements all work:

       

      get application.activeDocument().pathitems(1).subpathitems.item(1).pathpoints.item(1).anchor( )
      -- [265.5000, 74.0000]
      get application.activeDocument().pathitems(1).subpathitems.item(1).pathpoints.item(1).rightdi rection()
      -- [153.6624, 74.0000]
      get application.activeDocument().pathitems(1).subpathitems.item(1).pathpoints.item(1).leftdir ection()
      -- [377.3376, 74.0000]

       

      But, these are read only!  In order to modify the path, you have to have PathPointInfo or SubPathInfo.

       

      The documentation also says EntireSubPath will also work, but can't get there either.

       

      Does anyone know how to get to these values?

       

      Thank you!

        • 1. Re: How to get PathPointInfo or SubPathInfo?
          Michael L Hale Level 5

          You can't edit an existing path using scripting. You will need to read the path and convert into subPathInfo and pathPointInfo objects and either modify while converting or later after the conversion. Then delete the old path and make a new one from the edited info.

           

          Here is an example of extracting the info.

          function extractSubPathInfo(pathObj){
              var pathArray = new Array();// each element can be used as the second arugment in pathItems.add ie doc.pathItems.add("myPath1", [pathArray[0]]);
              var pl = pathObj.subPathItems.length;
              for(var s=0;s<pl;s++){
                  var pArray = new Array();
                    for(var i=0;i<pathObj.subPathItems[s].pathPoints.length;i++){
                       pArray[i] = new PathPointInfo;
                       pArray[i].kind = pathObj.subPathItems[s].pathPoints[i].kind;
                       pArray[i].anchor = pathObj.subPathItems[s].pathPoints[i].anchor;
                       pArray[i].leftDirection = pathObj.subPathItems[s].pathPoints[i].leftDirection;
                       pArray[i].rightDirection = pathObj.subPathItems[s].pathPoints[i].rightDirection;
                    };
                  pathArray[pathArray.length] = new Array();
                  pathArray[pathArray.length - 1] = new SubPathInfo();
                  pathArray[pathArray.length - 1].operation = pathObj.subPathItems[s].operation;
                  pathArray[pathArray.length - 1].closed = pathObj.subPathItems[s].closed;
                  pathArray[pathArray.length - 1].entireSubPath = pArray;
              };
              return pathArray;
          };
          var myPathInfo = extractSubPathInfo(app.activeDocument.pathItems.getByName('Path 1'));
          var myPathItem = app.activeDocument.pathItems.add("myNewPath", myPathInfo);
          
          1 person found this helpful
          • 2. Re: How to get PathPointInfo or SubPathInfo?
            bestwave Level 1

            Michael

             

            Thank you for your very helpful response.  Just knowing that a path cannot be modified in scripting would have saved me days of trying!

             

            I also thank you for your example of how to read the path points and create a new, modified path from it.

             

            The problem is that this is related to my earlier question from a couple of days back....  what I really need to do is put text on a circular path.  I know the path coordinates I need, but couldn't come up with a way to "stick" the text to a path I made myself, so I was trying to put text on a random path, then modify the coordinates to make it the right size.

             

            Now that I know it won't work that way, I can concentrate on finding a way to attach text to a new circular path.

             

            By the way, scriptlistener creates a script when you add text to a work path, which is 1300+ lines long, and does not work when you play it back!

             

            Thanks again, I will keep researching!!

            • 3. Re: How to get PathPointInfo or SubPathInfo?
              Laubender Adobe Community Professional & MVP

              Hi Michael,

              I know this thread is 8 years old, nevertheless it was one of the rare ones that is showing how to work with pathItems in the scripting DOM. I just tried to add a new pathItem to a document. Just a simple one, want to wet my feet with PhotoShop scripting. Seems to be very complicated, because the scripting guide did not provide a sample for method add() with pathItem. EDIT. Found a sample now and will test it.

               

              The rectangle I want to add can be described in pixels as:

              // [ [x1,y1] , [x2,y2] ]

              [ [ 421,1685 ] , [ 1525,2871 ] ]

               

              Before I dive into doc.pathItems.add() method I tried to skin an existing pathItem with the same coordinates in my PhotoShop CS6 document. So I tried your function extractSubPathInfo( pathObj ) on my document, but unfortunately it did not work as expected. A new named pathItem was added, I can see this in the Paths Panel, but it did not contain a shape of the right size in the right position:

              extractSubPathInfo-And-Add-a-new-pathItem-NOT-WORKING.PNG

               

              Do you know what went wrong?

              Provided of course I copied your code 1:1 to the ESTK's script window. There is no error message while executing the code.

              I'm on Windows 10 (1803) with PhotoShop CS6 Extended 13.1.2 x32.

               

              I zoomed out a bit. The new path is there!

              Just with wrong position and size. The proportions seem to be alright.

               

              extractSubPathInfo-And-Add-a-new-pathItem-NOT-WORKING-2.PNG

               

              What the heck is going on? I set the ruler units to Pixels.

              Do I have to reset another set of meassurements to get a exact duplicated result?

               

              Here the original:

               

              extractSubPathInfo-And-Add-a-new-pathItem-NOT-WORKING-3.PNG

               

              The dimensions of the document:

               

              extractSubPathInfo-And-Add-a-new-pathItem-NOT-WORKING-4.PNG

               

              Width: 4961 px

              Height: 7016 px

               

              21 x 29.7 cm

               

              Resolution: 600 ppi

              Mode: GRAYSCALE / 8 Bit per Channel

               

              Thanks,
              Uwe

              • 5. Re: How to get PathPointInfo or SubPathInfo?
                Laubender Adobe Community Professional & MVP

                Oh sh… , yes.

                Thanks for the link!

                 

                Regards,
                Uwe

                • 6. Re: How to get PathPointInfo or SubPathInfo?
                  pixxxel schubser MVP & Adobe Community Professional

                  Möchtest du einen Pfad kopieren oder einen neuen Pfad erstellen?

                   

                  Do you wish to copy a path item or to create a new one?

                  • 7. Re: How to get PathPointInfo or SubPathInfo?
                    Laubender Adobe Community Professional & MVP

                    I'm about to add a new path item.

                     

                    Still following the sample code from the PhotoShop JavaScript guide to add a pathItem.

                    Not a straight line like shown in pp 49-51, but a rectangle. It's nearly working!

                     

                    Two issues I have with that:

                     

                    1. The new shape is way too big and positioned wrong. Just like the function extractSubPathInfo( pathObj ) by Michael did.

                    2. I think I get the order of path points wrong. Did them clockwise and maybe I should do that counter-clockwise.

                     

                    Funny result:

                     

                    AddPath-FunnyResult-1.PNG

                    Here my code for this result:

                     

                    var doc = app.activeDocument;
                    
                    var lineArray = new Array();
                    
                    lineArray[0] = new PathPointInfo;
                    lineArray[0].kind = PointKind.CORNERPOINT;
                    lineArray[0].anchor = [ 421,1685 ] ;
                    lineArray[0].leftDirection = lineArray[0].anchor;
                    lineArray[0].rightDirection = lineArray[0].anchor;
                    
                    lineArray[1] = new PathPointInfo;
                    lineArray[1].kind = PointKind.CORNERPOINT;
                    lineArray[1].anchor = [ 1525,1685 ] ;
                    lineArray[1].leftDirection = lineArray[0].anchor;
                    lineArray[1].rightDirection = lineArray[0].anchor;
                    
                    lineArray[2] = new PathPointInfo;
                    lineArray[2].kind = PointKind.CORNERPOINT;
                    lineArray[2].anchor = [ 1525,2871 ] ;
                    lineArray[2].leftDirection = lineArray[0].anchor;
                    lineArray[2].rightDirection = lineArray[0].anchor;
                    
                    lineArray[3] = new PathPointInfo;
                    lineArray[3].kind = PointKind.CORNERPOINT;
                    lineArray[3].anchor = [ 421,2871 ] ;
                    lineArray[3].leftDirection = lineArray[0].anchor;
                    lineArray[3].rightDirection = lineArray[0].anchor;
                    
                    var lineSubPathArray = new Array();
                    lineSubPathArray[0] = new SubPathInfo;
                    
                    lineSubPathArray[0].operation = ShapeOperation.SHAPEXOR;
                    lineSubPathArray[0].closed = true;
                    lineSubPathArray[0].entireSubPath = lineArray;
                    
                    var myPathItem = doc.pathItems.add( "NewPathItem" , lineSubPathArray );
                    

                     

                    Let's test this in a different order of pathPointInfo.

                    Hm. Got the same false result. I guess I'm doing something wrong with property close or operation.

                     

                    FWIW: If I do this with InDesign's entirePath array on a added rectangle I see no problems.

                     

                    // InDesign code
                    
                    var doc = app.documents.add
                    (
                        {
                            documentPreferences : 
                            { 
                                pageWidth : "4961 Pt" , 
                                pageHeight : "7016 Pt" , 
                                facingPages : false 
                            }
                            
                        }
                    );
                    doc.viewPreferences.properties =
                    {
                        horizontalMeasurementUnits : MeasurementUnits.POINTS ,
                        verticalMeasurementUnits : MeasurementUnits.POINTS
                    };
                    
                    var rect = doc.rectangles.add();
                    
                    rect.paths[0].entirePath = 
                    [
                         [ 421,1685 ] ,
                         [ 1525,1685 ] ,
                         [ 1525,2871 ] ,
                         [ 421,2871 ]
                    ];
                    

                     

                    And this is leading to that rectangle with InDesign:

                     

                    AddPath-InDesign-1.PNG

                     

                     

                    Regards,
                    Uwe

                    • 8. Re: How to get PathPointInfo or SubPathInfo?
                      Laubender Adobe Community Professional & MVP

                      I'll give up for this evening. Let's see what the morning will bring :-)

                       

                      Best,
                      Uwe

                      • 9. Re: How to get PathPointInfo or SubPathInfo?
                        pixxxel schubser MVP & Adobe Community Professional

                        Guten Morgen Uwe

                         

                         

                        Zwei Anmerkungen:

                        1. Photoshop rechnet intern beim Auslesen und beim Setzen von Pfadpunkten immer in Pixeln und immer mit einer Auflösung von 72 PPI. Der einfachste Weg: rechne dein Dokument vorher ohne Neuberechnung auf 72 PPI herunter (und hinterher wieder hoch). Ansonsten musst du die Dokumentenauflösung mit einkalkulieren!
                        2. bei einem Rechteck müssen left- und rightDirection mit „ihren“ Ankerpunkten übereinstimmen. Also

                        lineArray[1].anchor = [ 1525,1685 ] ; 

                        lineArray[1].leftDirection = lineArray[1].anchor; 

                        lineArray[1].rightDirection = lineArray[1].anchor; 

                         

                        anstatt

                        lineArray[1].anchor = [ 1525,1685 ] ; 

                        lineArray[1].leftDirection = lineArray[0].anchor;

                        lineArray[1].rightDirection = lineArray[0].anchor; 

                         

                        Viele Grüße

                         

                        1 person found this helpful
                        • 10. Re: How to get PathPointInfo or SubPathInfo?
                          Laubender Adobe Community Professional & MVP

                          Hah! I knew it (not really.).

                          Copy/paste error with the direction values.

                          Thanks a lot that you spotted where I missed.

                           

                          Regards,
                          Uwe

                          • 11. Re: How to get PathPointInfo or SubPathInfo?
                            Laubender Adobe Community Professional & MVP

                            And I will calculate with document.resolution.

                            In my case a factor of 0.12.

                            Thanks again for that hint.

                             

                            Regards,
                            Uwe

                            • 12. Re: How to get PathPointInfo or SubPathInfo?
                              Laubender Adobe Community Professional & MVP

                              Hm…

                              Since I have control over the resolution of the psd document where I will add the rectangle, a rendered PDF, I think it would be wise to do a "simple" multiple of 72 for resolution like factor 10 that results in 720 ppi where no fractions in pixel calculation will occur. Yes, a factor of 10 seems sufficient for my project that implies cross-scripting PhotoShop from InDesign…

                               

                              Regards,
                              Uwe

                              • 13. Re: How to get PathPointInfo or SubPathInfo?
                                Laubender Adobe Community Professional & MVP

                                Here my code that is working very well:

                                 

                                var doc = app.activeDocument;
                                // All pixel values are meant with 72 ppi document resolution.
                                var res = doc.resolution;
                                var f = 72/res;
                                
                                var x1y1x2y2 = [ [ 421*f,1685*f ] , [ 1525*f,2871*f ]  ];
                                
                                var A = x1y1x2y2[0];
                                var B = [ x1y1x2y2[1][0] ,  x1y1x2y2[0][1] ];
                                var C = x1y1x2y2[1];
                                var D = [ x1y1x2y2[0][0] ,  x1y1x2y2[1][1] ];
                                
                                var ABCD = [ A , B , C , D ];
                                
                                var lineArray = new Array();
                                
                                for(var n=0;n<ABCD.length;n++)
                                {
                                    lineArray[n] = new PathPointInfo ;
                                    lineArray[n].kind = PointKind.CORNERPOINT ;
                                    lineArray[n].anchor = ABCD[n] ;
                                    lineArray[n].leftDirection = ABCD[n] ;
                                    lineArray[n].rightDirection = ABCD[n] ;
                                };
                                
                                
                                var lineSubPathArray = new Array();
                                lineSubPathArray[0] = new SubPathInfo;
                                
                                lineSubPathArray[0].operation = ShapeOperation.SHAPEXOR;
                                lineSubPathArray[0].closed = true;
                                lineSubPathArray[0].entireSubPath = lineArray;
                                
                                var myPathItem = doc.pathItems.add( "NewPathItem-6" , lineSubPathArray );
                                

                                 

                                AddPath-CorrectResult-1.PNG

                                 

                                Regards,
                                Uwe