Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Batch join anchor points

New Here ,
Jun 06, 2011 Jun 06, 2011

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.

TOPICS
Scripting
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jun 07, 2011 Jun 07, 2011

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

...
Translate
Adobe
Guide ,
Jun 07, 2011 Jun 07, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 07, 2011 Jun 07, 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.

Untitled-2.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 07, 2011 Jun 07, 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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 07, 2011 Jun 07, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 07, 2011 Jun 07, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 08, 2011 Jun 08, 2011
LATEST

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines