Skip to main content
Known Participant
July 19, 2017
Answered

How does the entirePath function cope with variables in curvy

  • July 19, 2017
  • 1 reply
  • 514 views

Hello,

I try to make cake pieces out of a circle with defined gaps between the cake pieces. The amount of pieces depend on what the user entered as number:

Below you see what I have. It makes cake oeices, but the connection between starting segment and ending segment is a straight line. Jongwares collection says:

entirePath:

A list of the coordinates of all of the path points on the path, including anchor points and left- and right-direction points. When creating a path using this property, supply either a list of anchor point coordinates ([[x1, y1], [x2, y2], ...]) or a list of anchor point, left-direction point, and right-direction point coordinates ([[[x1, y1], [x2, y2], [x3, y3]], [[x4, y4], [x5, y5], [x6, y6]], ...]). Note: Providing only anchor points results in a path on which all of the path points are connected with straight line segments; supplying the positions of left- and right-direction points specifies curved line segments. Can return: Array of Arrays of 2 Units.

I understand it like this:

if I want to have a straight line, you just give coordinates single points composing of x and y

e.g. for a triangle

var path = entirePath([ [x1, y1], [x2,y2], [x3,y3] ]);

if I want to have one curved line, you need to add the coordinates of the ends of the right and left handle to the points composing of x and y

e.g. for a triangle

var path = entirePath([ [x1, y1], [x2,y2], [ [x3_1,y3_1], [x3_2,y3_2], [x3_3,y3_3] ] ]);

Now I wrote in my example the variable myPath in line 62. And I get an error message marking line 63 "entirePath", no other information, I have no clue were the mistake is.

So if anybody has an idea were my mistake is, I would appreciate the help.

Best

Cleo

var myDocument = app.documents.add();

    var myOutsideY1 = 70;

    var myOutsideX1 = 210;

    var myOutsideY2 = myOutsideY1+450;

    var myOutsideX2 = myOutsideX1+450;

    var myCircleOutside = myDocument.ovals.add({

                                    geometricBounds: [myOutsideY1, myOutsideX1, myOutsideY2, myOutsideX2],

                                    //fillColor: "Farbcode",

                                    strokeWeight: 2,

                                    //strokeColor: myBlack,

                                    name: "outside"

                                    });

    var myInsideY1 = myOutsideY1+20;

    var myInsideX1 = myOutsideX1+20;

    var myInsideY2 = myInsideY1+410;

    var myInsideX2 = myInsideX1+410;

    var myCircleInside = myDocument.ovals.add({

                                    geometricBounds: [myInsideY1, myInsideX1, myInsideY2, myInsideX2],

                                    //fillColor: "Farbcode",

                                    strokeWeight: 1,

                                    //strokeColor: myBlack,

                                    name: "inside"

                                    });

                       

     

      // selecting the inner circle to split it in the right amount of FoFes

      app.select( app.activeDocument.pageItems.item("inside")); 

      // asking for the amount of FoFes with the "prompt()" function

      var myFoFe = prompt("Bitte geben Sie ein ganzzahlige Anzahl an Forschungsfeldern an: ");

      // checking if something has to be entered and the number entered is higher than 1

      if (myFoFe != null && myFoFe > 1){

          // determining the different variables to calculate later the angles for the segments

            var myGapSize = 4.5; // place between the FoFe segments

            var myGapSpace = myGapSize*myFoFe; // how much space the gaps take in total

            var myFoFeSize = (360-myGapSpace)/myFoFe; // 360° - all the degrees the gaps will take, calculating what is left for the FoFe segments

  //     alert(myFoFeSize, "myFoFeSize");

            var myFoFeAngle = myFoFeSize*(Math.PI/180);        // javascript is calculating in radians, that is why the angle has to be converted from degree to radians: radians = degrees * (Math.PI/180)

            var myGapAngle = myGapSize*(Math.PI/180);

            // determine the center and the radius of my selected circle

            var myCircleCenter = [(app.selection[0].geometricBounds[3]+app.selection[0].geometricBounds[1])/2, (app.selection[0].geometricBounds[2]+app.selection[0].geometricBounds[0])/2];

            var myCircleRadius = Math.max ((app.selection[0].geometricBounds[3]-app.selection[0].geometricBounds[1])/2, (app.selection[0].geometricBounds[2]-app.selection[0].geometricBounds[0])/2);

   //    alert(myCircleCenter, "myCircleCenter");

   //    alert(myCircleRadius, "myCircleRadius");

            // generating the fragments

             var myStartAngle = 0;

             for (i=0; i<myFoFe; i++){   // the loop is going as often as FoFes were chosen

  //     alert(myFoFe, "tells how many times the for loop is running");

                        var myEndAngle = myStartAngle + myFoFeAngle;

  //     alert(myEndAngle, "myEndAngle");

                          // warning: math! (though this is SIMPLE compared to what I've bin doing today) 

                        var mySegmentStart = [myCircleCenter[0] + myCircleRadius*Math.sin(myStartAngle), myCircleCenter[1] - myCircleRadius*Math.cos(myStartAngle)];    // coordinates for the end of the path which defines the start of the segment (this is just a point)

                        var mySegmentEnd = [myCircleCenter[0] + (myCircleRadius*Math.sin(myEndAngle)), myCircleCenter[1] - myCircleRadius*Math.cos(myEndAngle)];

    

                        // create surrounding border 

                        var mySegmentBorder = app.activeDocument.graphicLines.add();

                        var myNinteeAngle = 90*(Math.PI/180);

                        var myPath = [myCircleCenter, [mySegmentStart, (myStartAngle+myNinteeAngle)], [mySegmentEnd, (myEndAngle - myNinteeAngle)]]; // noch dran hängen an "myPath"

                        mySegmentBorder.paths[0].entirePath = myPath;

                        mySegmentBorder.paths[0].pathType = PathType.CLOSED_PATH;

                         

                        myStartAngle = myEndAngle + myGapAngle;

                          

                   } // end of for-loop

// here naming all polygone (choose all items named "Polygon" and give them labels/names: poly1 - poly xy

       

       } // end of if

  

else {alert("Die Zahl muss größer asein")};

   } // end of if

  

This topic has been closed for replies.
Correct answer Jongware

"entirePath" expects an array of single points (an array of [x,y]), OR point/left control/right control triplets (an array of [ [x,y], [lcx,lcy], [rcx,rcy] ]). Mind you, I'm never sure about the exact order of these last three. My documentation is what Adobe told me, and I could be mistaken but I think there is an error somewhere.

However, I am sure that it should be either one coordinate pair or three pairs. Your code, which, by the way looks very good despite being not-working, contains a mix of coordinate pairs and this element:

(myStartAngle + myNineteeAngle)

of which I cannot readily see what type it is. It cannot be a coordinate pair because you can't add arrays this way.

Best way to proceed: manually draw a segment, then inspect what its entirePath returns, and use that as a template for your own calculations.

1 reply

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
July 19, 2017

"entirePath" expects an array of single points (an array of [x,y]), OR point/left control/right control triplets (an array of [ [x,y], [lcx,lcy], [rcx,rcy] ]). Mind you, I'm never sure about the exact order of these last three. My documentation is what Adobe told me, and I could be mistaken but I think there is an error somewhere.

However, I am sure that it should be either one coordinate pair or three pairs. Your code, which, by the way looks very good despite being not-working, contains a mix of coordinate pairs and this element:

(myStartAngle + myNineteeAngle)

of which I cannot readily see what type it is. It cannot be a coordinate pair because you can't add arrays this way.

Best way to proceed: manually draw a segment, then inspect what its entirePath returns, and use that as a template for your own calculations.

Cleo_helmAuthor
Known Participant
July 21, 2017

Hey,

it is based mainly on your script, this is probably the part which looks good.

Concerning the array for entirePath I figured out the locations of the coordinates for the handles:

So I'm still working on the calculation for the coordinates, I will keep the "discussion" updated when I finally have nice pieces.