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.

Enter the number of sides value.

And your polygon is ready…

[wpdm_file id=33]

[fancy_header variation=”orange”]Code[/fancy_header]

#target Illustrator

// = 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 – 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));



[fancy_header variation=”orange”]Donate to Carlos Canto[/fancy_header]



1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.