Skip to main content
November 23, 2012
Answered

How create freeform paths shape using script?

  • November 23, 2012
  • 1 reply
  • 2877 views

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

This topic has been closed for replies.
Correct answer Jongware

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).

1 reply

Jongware
Community Expert
Community Expert
November 23, 2012

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];

November 26, 2012

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.

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
November 26, 2012

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).