Copy link to clipboard
Copied
I am wondering if someone can help me write a script to batch join a series of anchor points. I have a map with multiple locations that need to be joined simply with straight-line 2 point vector paths. Each anchor point needs to be joined to all the other anchor points seperately to create a sort of a web. For example if you had ten points and you started with one then you'd need to join it to all other nine points and for the next you'd have to join it to the remaining eight, and then seven, and so on. Problem is there are several hundred anchor points. Any help would be much appreciated.
Wooooooooo… I may have got it now… My head logic of the needing to spit was plain wrong… Try this…
...#target illustrator var doc = app.activeDocument; var sel = doc.selection; var pp = Array(); for ( var i = 0; i < sel.length; i++ ) { if ( sel.typename == 'PathItem' ) { pp.push(sel.pathPoints[0].anchor); } } if (pp.length >= 2) { do { for ( var j = 1; j < pp.length; j++ ) { var line = doc.path
Copy link to clipboard
Copied
You would possibly be better posting a couple of screen shots of your intentions as this does not appear so obvious…
Copy link to clipboard
Copied
I need my end product to resemble something similar to this, only more complete and exact--like an airline map. Ideally I would like to be able to designate a certain number of anchor points with the pen tool and highlight all of them to join with paths, only the join tool creates one path. Every point needs to be joined to every other point on the map with a separate path.
Copy link to clipboard
Copied
I had a go at this and something with my math/thinking is a miss… While with lots of points it looks like it does the job with only a half dozen you will see its missed some out… I will see if I can get my head around this… math is not my strongest point (where's jong when you need him). May be someone else can spot the error while I smash my head on the desk again…
This is how I tried…
#target illustrator
var doc = app.activeDocument;
var sel = doc.selection;
var pp = Array();
for ( var i = 0; i < sel.length; i++ ) {
if ( sel.typename == 'PathItem' ) {
pp.push(sel.pathPoints[0].anchor);
}
}
//$.writeln(pp.length);
//$.writeln(pp.toString());
var split = Math.round(pp.length/2);
do {
for ( var j = 1; j < pp.length; j++ ) {
var line = doc.pathItems.add();
lpp = Array();
lpp.push(pp[0]);
lpp.push(pp
Copy link to clipboard
Copied
Wooooooooo… I may have got it now… My head logic of the needing to spit was plain wrong… Try this…
#target illustrator var doc = app.activeDocument; var sel = doc.selection; var pp = Array(); for ( var i = 0; i < sel.length; i++ ) { if ( sel.typename == 'PathItem' ) { pp.push(sel.pathPoints[0].anchor); } } if (pp.length >= 2) { do { for ( var j = 1; j < pp.length; j++ ) { var line = doc.pathItems.add(); lpp = Array(); lpp.push(pp[0]); lpp.push(pp
); line.setEntirePath(lpp); app.redraw(); $.sleep(500); } pp.shift(); } while (pp.length >= 2) app.redraw(); }
Copy link to clipboard
Copied
So far that script has been working perfectly. I haven't run it on my final array of several hundred anchor points and am not quite sure how long it will take to render it all but seems to be working with the samples i've put in. thanks again.
Copy link to clipboard
Copied
I had to slow this down so that I could visualize where it was going wrong the first time… There are 2 lines in the script that you can either comment out or remove completely that should speed up the script quite a lot if you have a high number of points… I have commented them out for you so you can see how to use this if you so wish…
#target illustrator
var doc = app.activeDocument;
var sel = doc.selection;
var pp = Array();
for ( var i = 0; i < sel.length; i++ ) {
if ( sel.typename == 'PathItem' ) {
pp.push(sel.pathPoints[0].anchor);
}
}
if (pp.length >= 2) {
do {
for ( var j = 1; j < pp.length; j++ ) {
var line = doc.pathItems.add();
lpp = Array();
lpp.push(pp[0]);
lpp.push(pp);
line.setEntirePath(lpp);
// app.redraw(); This line causes the app to redraw the screen (slow)…
// $.sleep(500); This line locks up the script for 0.5 seconds (slower)…
}
pp.shift();
} while (pp.length >= 2)
app.redraw();
}
It now should only redraw the screen the once when done…
Find more inspiration, events, and resources on the new Adobe Community
Explore Now