Skip to main content
Participant
June 6, 2011
Answered

Batch join anchor points

  • June 6, 2011
  • 1 reply
  • 2324 views

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.

This topic has been closed for replies.
Correct answer Muppet_Mark-QAl63s

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);                      line.setEntirePath(lpp);      }      pp.shift();            //$.writeln(pp.length);      //$.writeln(pp.toString()); } while (pp.length >= split) app.redraw();


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(); }

1 reply

Muppet_Mark-QAl63s
Inspiring
June 7, 2011

You would possibly be better posting a couple of screen shots of your intentions as this does not appear so obvious…

Participant
June 7, 2011

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.

Muppet_Mark-QAl63s
Inspiring
June 7, 2011

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);                      line.setEntirePath(lpp);      }      pp.shift();            //$.writeln(pp.length);      //$.writeln(pp.toString()); } while (pp.length >= split) app.redraw();