Advertisement


Illustrator: How to draw circles at control points?


Question

I drew a polygon using the pen tool. Now I'd like to draw small circles (illustrating vertices) at the polygon control points.

2015/04/21
1
-1
4/21/2015 6:04:00 PM

Accepted Answer

As per request, a script to do this on selected paths. This is an alternative for @CConroy answer that may make things easier to do in the long run. It draws symbols on points and tangents and connects the tangents with lines, You can use symbols palette to change how they look after the fact. Might be useful for somebody.

Put following in a .jsx file and run it with paths selected:

#target illustrator

main();

function main(){
  var sym = createSymbolsIfNeeded(activeDocument);
  handlePaths(activeDocument.selection, 
              sym.anchor, sym.tangent); 
  // pass undefined for sym tangent if you dont want 
  // tangent handles.
}

function handlePaths(sel, symAcnhor, symDir) {
  for(var i = 0; i < sel.length; i++){
      if(sel[i].typename == "PathItem"){
          symbolsOnPoints(sel[i], symAcnhor, symDir);
      }
      // you would possibly need to recurse
      // the groups and compound paths in some 
      // cases.
  }
}

function symbolsOnPoints(path, symAcnhor, symDir) {
  var pts = path.pathPoints;
  for(var i = 0; i < pts.length; i++){
      var pos = pts[i].anchor

      if(!(symDir === undefined)) {
        var pos2 = pts[i].rightDirection;
        if (dist(pos, pos2) > 0.1){
          drawLine(pos, pos2);
          centeredSymbol(pos2, symDir);
        }

        pos2 = pts[i].leftDirection;
        if (dist(pos, pos2) > 0.1){
          drawLine(pos, pos2);
          centeredSymbol(pos2, symDir);
        }
      }

      centeredSymbol(pos, symAcnhor);
  }
}

function centeredSymbol(pos, symbol) {
  var p = pos.slice(0);
  sym = activeDocument.symbolItems.add(symbol);
  p[0] -= sym.width/2.0;
  p[1] += sym.height/2.0;   
  sym.position = p;
  return sym;
}

function drawLine(p1, p2) {
    var line = activeDocument.pathItems.add();
    line.setEntirePath([p1,p2]);
    return line;
}

function dist(a, b){

  return Math.sqrt(Math.pow(b[0]-a[0], 2) + 
                   Math.pow(b[1]-a[1], 2));        
}

function createSymbolsIfNeeded(doc){
    var symAnchor;
    try {
        symAnchor = doc.symbols.getByName("Anchor");
    }
    catch(err) {
        var circle = doc.pathItems.ellipse(5,5,5,5);
        symAnchor = doc.symbols.add(circle);
        symAnchor.name = "Anchor";
        circle.remove();
    }

    var symTangent;
    try {
        symTangent = doc.symbols.getByName("Tangent");
    }
    catch(err) {
        var rect = doc.pathItems.rectangle(5,5,5,5);
        var symTangent = doc.symbols.add(rect);
        symTangent.name = "Tangent";
        rect.remove();
    }
    return {anchor : symAnchor, tangent: symTangent};
}

    tangents

Image 1: Example result. You can easily change the different marker symbols win the symbol palette.

PS: The script is not really super secure and stable because its one of my own scripts for quick documentation so be careful.

PPS: I have pushed this code to bitbucket

2015/04/03
7
4/3/2015 8:22:00 PM

Start by drawing a line and circle and style each how you would like the polygon sides and vertices to look.

Drag the line to the Brushes panel and choose Pattern Brush. In the Pattern Brush Options dialog, set the first tile (Outer Corner) to None and hit OK.

Then, Option-drag your circle onto the Brushes Panel into that first tile slot. You'll return to the Pattern Brush Options dialog, but now your circles will be in place of all the vertices (the corners basically). Repeat the option-drag for the 3 remaining brush tiles.

enter image description here

2015/04/02