Polygon By Side Adobe Illustrator Script

Polygon By Side AI Script

0

This post has already been read 4285 times!

Again simple but powerful script by Carlos Canto. This one creates polygons with custom number of  sides and length. Illustrator by default only creates polygons by radius.

Execute your script via Scripts folder or simply use Script Bay panel (makes things much easier. Read this  article.)

Enter the length value of each side.

Polygon_By_Side_01

Enter the number of sides value.

Polygon_By_Side_02

And your polygon is ready…

Polygon_By_Side_03

Code

#target Illustrator

// script.name = polygonBySide.jsx;
// script.description = creates a polygone based on side length;
// script.required = an open document;
// script.parent = CarlosCanto; // 11/21/13;
// script.elegant = false;
// Shared via Creativetuts.com – Author : Carlos Canto
if (app.documents.length>0) polygonBySide ();
else alert (“no document to draw the polygon”);

function polygonBySide() {
var title = “Create Polygon by Side”;
var sideLen = Number(prompt (“Enter Side Length in Points”, 20, title));
var numberOfSides = Number(prompt (“Enter number of sides”, 5, title));

//var s = 2*r*Math.sin(Math.PI/n); // side length = 2*radius*sin(180 deg/number of sides)
var radius = sideLen/(2*Math.sin(Math.PI/numberOfSides));

var idoc = app.activeDocument;
var ctr = idoc.activeView.centerPoint;
dw = idoc.width;
dh = idoc.height;
wc= dw /2;
hc = dh *-0.5;
var ipoly = idoc.pathItems.polygon (ctr[0], ctr[1], radius, numberOfSides);
ipoly.position = Array(wc-(ipoly.width/2),hc+(ipoly.height/2));

}

Donate to Carlos Canto

Leave a Reply