8 Replies Latest reply on Apr 30, 2014 8:34 AM by dancemantron

    How to select the outermost pathPoints in Compound or Grouped pathItems?

    dancemantron Level 1

      Hello Hiroyuki, Carlos and AISComm.,

       

      i have an number of paths in a group each filled with single colors.

      3) I hoped there is a way to select the outermost pathPoints on the perimeter of the group?

       

      The following script i just found by wysiwygbill at: http://forums.adobe.com/message/3046178#3046178  ..,he writes: "..it's supposed to return the outermost bounds of the group". So it may save time in adapting it to select the points at the outermost bounds.

      Please let me know if this is helpful and can be done?

       

      Thanks as always, for your valued help and effective coding,

      Jeff

       

       

      function getRealVisibleBounds(grp) {

           var outerBounds = [];

           for(var i = grp.pageItems.length - 1; i >= 0;i--)  {

                var bounds = [];

                if(grp.pageItems[i].typename == 'GroupItem') {

                     bounds =  getRealVisibleBounds(grp.pageItems[i]);

                }

                else if((grp.pageItems[i].typename == 'PathItem' || grp.pageItems[i].typename == 'CompoundPathItem')

                     && (grp.pageItems[i].clipping || !grp.clipped)) {

                     bounds = grp.pageItems[i].visibleBounds;

                }

                if (bounds.length > 0) {

                     outerBounds = maxBounds(outerBounds,bounds);

                }

           }

           return (outerBounds.length == 0) ? null : outerBounds;

      }

       

      function maxBounds(ary1,ary2) {

           var res = [];

           if(ary1.length == 0)

                res = ary2;

           else if(ary2.length == 0)

                res = ary1;

           else {

                res[0] = Math.min(ary1[0],ary2[0]);

                res[1] = Math.max(ary1[1],ary2[1]);

                res[2] = Math.max(ary1[2],ary2[2]);

                res[3] = Math.min(ary1[3],ary2[3]);

           }

           return res;

      }

       

      function positionVisible(grp,x,y)

      {

           var bounds = getRealVisibleBounds(grp);

           var newX = x + (grp.left - bounds[0]);

           var newY = y + (grp.top - bounds[1]);

           grp.position = [newX,newY];

      }

        • 1. Re: How to select the outermost pathPoints in Compound or Grouped pathItems?
          pixxxel schubser Level 5

          dancemantron wrote:

           

          … I hoped there is a way to select the outermost pathPoints on the perimeter of the group? …

           

          At first, the function maxBounds() in your linked thread seems to be not bad. And clipping paths are taken into account - if you need this feature.

           

           

          Perhaps this could be helpful for you also:

           

          http://forums.adobe.com/message/6130080#6130080

          or this:

          http://forums.adobe.com/message/5213407#5213407

           

          Have fun

           

          • 2. Re: How to select the outermost pathPoints in Compound or Grouped pathItems?
            HiroyukiSato

            Hi Jeff,

            It depends on what you intend to do after selecting the pathPoints.

            If you create an united shape with Pathfinder, you can get the outermost points by its anchors.

            But this way is not enough, is it?

            • 3. Re: How to select the outermost pathPoints in Compound or Grouped pathItems?
              CarlosCanto Adobe Community Professional & MVP

              with CS6 and newer, you could "unite" the group or compound path and expand, then you'll end up with one path where you could get the points. if you want to keep the original paths, you can make a duplicate first.

              • 4. Re: How to select the outermost pathPoints in Compound or Grouped pathItems?
                dancemantron Level 1

                Hello AISComm.,

                                          and thanks again Hiroyuki and Carlos, as always your instructions are spot on! Unfortunately my project plugin produces a Layer > pathItem structure that is emptied(or deleted) whenever i apply the Pathfinder Unite !?

                So i've tried a different approach: 1st i manually select the points(from multiple paths) i need to align with the highest point in that selection, then 2nd write\use a script that reads and stores those selected points in an Array. Then use those array points to select each subsequent Layers pathPoints to apply the same alignment thru automation.

                 

                i'll  paste  scripts below that,..

                a) successfully counts selected pathPoints in pathItem[1] and stores that count in an Array, THEN,..

                b) a 2nd script that is supposed to 1st count the number of selected pathItems, then count their selected pathPoints and store them in another Array,..

                ..but this 2nd script fails for reasons i cannot yet diagnose.

                 

                So i hoped you could please,.

                1) ..help to debug or correct\rewrite this 2nd script,

                2) and perhaps suggest the best way to map or expand elliptical or curved path edges(and their fills) into a Rectangle?

                 

                The reason this must be done is because i plan to use these paths as Envelopes to be distorted into roto paths. But before that can be done, each envelope path must be mapped into a Rectangle, otherwise the resulting envelope distort contains gaps, created from the space between the envelope path and its' rectangular bounding box.

                 

                Lastly, i'll try and paste the 2nd script below but please describe how to attach a script legibly since pasting here does not retain code structure unless its copied from here and pasted to text file.

                Thanks again for all your help,

                biggest fan, Jeff

                 

                 

                var paths     = app.activeDocument.pathItems;

                var pointCount = countSelectedPathPoints(paths);

                alert(pointCount);                                                                                           // = 0,1,2,..

                function countSelectedPathPoints(path){


                var h   = 0;

                var i    = 0;

                var count = 0;

                var pointsSel = Array();

                //var paths = app.activeDocument.pathItems;



                for (h=0; h<path.length; h++)

                {

                if (path[h].selected == true)

                {

                for (i=0; i<path[h].pathPoints.length; i++)

                {

                if (path[h].pathPoints[i].selected == PathPointSelection.ANCHORPOINT)

                {

                count++

                pointsSel.push(path[h].pathPoints[i]);

                alert(pointsSel[i]);                                                            // = [pathPoints],..

                }

                }

                return count;

                }

                }

                }

                • 5. Re: How to select the outermost pathPoints in Compound or Grouped pathItems?
                  dancemantron Level 1

                  Thanks aswell Pixxxel Pchubser,

                                                                       your links revealed some additional approaches,

                  J

                  • 6. Re: How to select the outermost pathPoints in Compound or Grouped pathItems?
                    Larry G. Schneider Adobe Community Professional & MVP

                    In the Upper Right of the reply dialog is the line Use Advanced Editor. Click on that and then use the double blue carets to select the scripting syntax you wish to show.

                     

                    Screen shot 2014-04-28 at 9.25.13 AM.png

                    • 7. Re: How to select the outermost pathPoints in Compound or Grouped pathItems?
                      dancemantron Level 1

                      Thanks Larry,

                                            i'll make use of that right away.

                      J

                      • 8. Re: How to select the outermost pathPoints in Compound or Grouped pathItems?
                        dancemantron Level 1

                        Hello Hiroyuki, Carlos and AISComm.,

                        ...i hope i did'nt ask for too much with my last message?, sorry if thats the case, or perhaps your real busy, have left or otherwise unavailable.

                        I continue researching answers as always, but if\when you have a moment i hope you can help with this last problem diagnosing the almost working script in my last msg. and\or suggest the best way to map or expand elliptical or curved path edges into a Rectangular shape?

                        Thanks again for any and all help,

                        Jeff