8 Replies Latest reply on Nov 26, 2012 11:48 AM by Trevorׅ

    How create freeform paths shape  using script?

    Bill joy Level 1

      Hi

      I want to create a shape in which i add multiple points

      i try using GraphicLine  but it add no path point in this

       

      var myGraphicLine = myPage.graphicLines.add();

      myGraphicLine.paths.item(0).pathPoints.item(0).anchor = [72, 72];

      myGraphicLine.paths.item(0).pathPoints.item(1).anchor = [72, 144];

      myGraphicLine.paths.add();

      myGraphicLine.paths.item(1).pathPoints.item(0).anchor = [72, 144];

      myGraphicLine.paths.item(1).pathPoints.item(1).anchor = [90, 100];

      myGraphicLine.paths.add();

      myGraphicLine.paths.item(1).pathPoints.item(0).anchor = [90, 100];

      myGraphicLine.paths.item(1).pathPoints.item(1).anchor = [110, 144];

      myGraphicLine.paths.add();

      myGraphicLine.paths.item(1).pathPoints.item(0).anchor = [110, 144];

      myGraphicLine.paths.item(1).pathPoints.item(1).anchor = [144, 72];

       

      I  want to create a W type shape using script.

      How create a freeform paths type shape (like those drawn with the Pencil or Pen tools)  using js ?


      Thanks

        • 1. Re: How create freeform paths shape  using script?
          [Jongware] Most Valuable Participant

          Bill joy wrote:

           

           

          How create a freeform paths type shape (like those drawn with the Pencil or Pen tools)  using js ?

           

          You add a graphicLine, which creates a default single path with two path points. Then you add more paths to these, but a new path is initially empty. So you cannot change 'pathPoints' right away, you have to add them first.

           

          In addition, you keep referring to item(1) of paths, where you should have incremented the number with each new path.

           

          var myGraphicLine = myPage.graphicLines.add();
          myGraphicLine.paths.item(0).pathPoints.item(0).anchor = [72, 72];
          myGraphicLine.paths.item(0).pathPoints.item(1).anchor = [72, 144];
          myGraphicLine.paths.add();
          myGraphicLine.paths.item(1).pathPoints.add();
          myGraphicLine.paths.item(1).pathPoints.item(0).anchor = [72, 144];
          myGraphicLine.paths.item(1).pathPoints.item(1).anchor = [90, 100];
          myGraphicLine.paths.add();
          myGraphicLine.paths.item(2).pathPoints.add();
          myGraphicLine.paths.item(2).pathPoints.item(0).anchor = [90, 100];
          myGraphicLine.paths.item(2).pathPoints.item(1).anchor = [110, 144];
          myGraphicLine.paths.add();
          myGraphicLine.paths.item(3).pathPoints.add();
          myGraphicLine.paths.item(3).pathPoints.item(0).anchor = [110, 144];
          myGraphicLine.paths.item(3).pathPoints.item(1).anchor = [144, 72];
          
          1 person found this helpful
          • 2. Re: How create freeform paths shape  using script?
            Bill joy Level 1

            Thanks Jongware for Reply

            It create a W type shape But it not work like freeform paths type shape (like those drawn with the Pencil or Pen tools). When I select Anchor point in this shape it not work like freeform paths.

            I want to create freeform paths shape.When I move Anchor point then path is disconnect in shape.

             

            Thanks.

            • 3. Re: How create freeform paths shape  using script?
              [Jongware] Most Valuable Participant

              That is because you are creating separate paths. Create just the first one, and then add all pathpoints to it.

               

              Remember that the very first path you create comes with 2 free first points, so just move these into position as above. Then add the new points to the same path, instead of creating new ones (lines #4, #8, and #12 in my example).

              • 4. Re: How create freeform paths shape  using script?
                Bill joy Level 1

                Thanks Jongware for Reply

                Now it work well as freeform paths shape.

                 

                Thanks

                • 5. Re: How create freeform paths shape  using script?
                  Muppet Mark Level 5

                  You could also set the whole shape on one go… Not my best W but you get the idea…

                  var doc = app.activeDocument;
                  
                  var shape = doc.spreads.firstItem().rectangles.add();
                  
                  shape.paths.firstItem().entirePath = [
                  [20,32],[35,116],[65,114],[77,85],[81,113],[107,114],[107,84],[122,114],
                  [143,114],[160,22],[122,20],[114,62],[93,21],[64,23], [63,67],[45,22]
                  ];
                  
                  • 6. Re: How create freeform paths shape  using script?
                    [Jongware] Most Valuable Participant

                    There are many ways to add paths. However, at some point the readability starts to suffer (so keep in mind Bill joy is still struggling with the basic concepts).

                     

                    But

                     

                    I see your whole shape-at-a-go and raise with the same thing as a one-liner. It's also a proper 'W' -- Lithos Pro Regular (admittedly with the subtle curving and ink-traps removed).

                     

                    app.layoutWindows[0].activePage.ovals.add().paths[0].entirePath = [ [167,69],[147,123],[123,82],[100,125],[81,68],[72,72],[97,144],[123,98],[147,141],[176,73],[167,69] ];
                    
                    • 7. Re: How create freeform paths shape  using script?
                      Muppet Mark Level 5

                      A slightly better w indeed… I concede…

                      • 8. Re: How create freeform paths shape  using script?
                        Trevorׅ Adobe Community Professional

                        Let's say I want the bottoms of the W flatter.

                        So I want to add points to the W

                        I can add points using splice and entirePath but is there a different way to add the extra points that doesn't envole using entire path and therefore not require the redrawing of the whole shape?

                        Please write a nicer code than this one.

                        Thanks,

                        Trevor

                         

                        JongwaresW =  [ [167,69],[147,123],[123,82],[100,125],[81,68],[72,72],[97,144],[123,98],[147,141],[176,73],[167,69] ];
                        w = app.layoutWindows[0].activePage.ovals.add()
                        w.paths[0].entirePath = JongwaresW;
                        JongwaresW.splice(6,0,[85,145]);
                        JongwaresW.splice(10,0,[157,145]);
                        w .paths[0].entirePath = JongwaresW;