Sg2.9
Breakapart or Exploder Tool
Recent RSS
Breakapart or Exploder Tool
From:  DArtagnon
Date:  10. November 2008, 22:44

I'd like to be able to break a long path into its individual segments so that I can apply a brush stroke to them individually, instead of along the whole path.

The scissors tool works if you only want to do it a couple of times, but anything more becomes tedious.

It seems like it could be as easy as:

For every point in a path,

completely copy point 1 and point 2, connect them.
completely copy point 2 and point 3, connect them...
...completely copy point lastPoint and point 1, connect them.

But I don't know any scripting or how to do that.

TIA,

dartagnon.reid@gmail.com

Re: Breakapart or Exploder Tool
Date:  10. November 2008, 23:33

Download the attached script, put it in your scripts folder, select a path, select the script and press play

var selectedPath = activeDocument.selectedItems[0];
var segments = selectedPath.segments;
var l = segments.length;

for(var i=1; i<l; i++) {
	new Path([segments[i-1], segments[i]]);
}

selectedPath.remove()
Re: Breakapart or Exploder Tool
From:  DArtagnon
Date:  11. November 2008, 22:03

Thanks, that works pretty well. Only problem is that it doesn't copy the last segment. The script I finally came up with (and I didn't check back here until I was done) is:
(Questions at the bottom)

[code]
//Grabs the selected paths from the current page.
var mySelection = app.activeDocument.selection;

//Starts a loop to iterate for every selected path
for (i=0; i<mySelection.length; i++)
{
//Starts a loop to iterate for every point in a given path
for (j=0; j<mySelection[i].pathPoints.length; j++)
{
//Create a new path, mySegment, and put a new set of points in it, myPoints
var mySegment = activeDocument.pathItems.add();
var myPoint1 = mySegment.pathPoints.add();
var myPoint2 = mySegment.pathPoints.add();

//Stroke the path so I can see the results
mySegment.stroke = true;

//Set all of the first point's attributes to the original copy's

myPoint1.anchor = mySelection[i].pathPoints[j].anchor;
myPoint1.leftDirection = mySelection[i].pathPoints[j].leftDirection;
myPoint1.rightDirection = mySelection[i].pathPoints[j].rightDirection;
myPoint1.pointType = mySelection[i].pathPoints[j].pointType

/*
Set all of the second's. If it's copying the last point on the path,
the next point is the first. This creates an extra segment when dealing
with un-closed paths; delete it by hand.
*/

if (j==mySelection[i].pathPoints.length - 1)
{
myPoint2.anchor = mySelection[i].pathPoints[0].anchor;
myPoint2.leftDirection = mySelection[i].pathPoints[0].leftDirection;
myPoint2.rightDirection = mySelection[i].pathPoints[0].rightDirection;
myPoint2.pointType = mySelection[i].pathPoints[0].pointType
}
else
{
myPoint2.anchor = mySelection[i].pathPoints[j+1].anchor;
myPoint2.leftDirection = mySelection[i].pathPoints[j+1].leftDirection;
myPoint2.rightDirection = mySelection[i].pathPoints[j+1].rightDirection;
myPoint2.pointType = mySelection[i].pathPoints[j+1].pointType
}
}
}[/code]

I'm using the CS2 version, what should I make different about the above so that I can use it as a Scriptographer script? And how do I make a code block on this forum?

Re: Breakapart or Exploder Tool
Date:  12. November 2008, 01:33

Here is the adjusted code to make the script work for closed paths as well:

var selectedPath = activeDocument.selectedItems[0];
var segments = selectedPath.segments;
var l = segments.length;

for(var i=1; i<l; i++) {
	new Path([segments[i-1], segments[i]]);
}

// if the path is closed, create a path with
// the first and last points of the selectedPath
if(selectedPath.closed)
	new Path([segments[l-1], segments[0]]);

selectedPath.remove()
Quote:
I'm using the CS2 version, what should I make different about the above so that I can use it as a Scriptographer script?

http://www.scriptographer.com/Reference/
If you have any specific questions, feel free to ask!

Quote:
And how do I make a code block on this forum?

Use the help button to see the different possible tags (just next to the attach file button on the bottom left)

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Stroke <-> Fill 09.01.08