Skip to content

Instantly share code, notes, and snippets.

@joshbduncan
Created January 19, 2023 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbduncan/bfec15dcbe5e05cf55ee9b6f77c97463 to your computer and use it in GitHub Desktop.
Save joshbduncan/bfec15dcbe5e05cf55ee9b6f77c97463 to your computer and use it in GitHub Desktop.
Ai Create Inset Rectangles and Ellipses
// Create inset rectangles and ellipses and place into compound path
var doc = app.activeDocument;
var al = doc.activeLayer;
// type of path
// var type = "rectangle"
var pathType = "ellipse";
// amount of inset paths (max: 4)
var paths = 3;
// set outside path size (points)
var width = 360;
var height = 360;
// set inset amount (points)
var inset = 18;
// create color
var newColor = new RGBColor();
newColor.red = 0;
newColor.green = 0;
newColor.blue = 0;
// make compound path
var cp = al.compoundPathItems.add();
// make paths and insert in compound path
var path, pathInset, pathW, pathH;
for (var i = 0; i < paths + 1; i++) {
// calculate path size and position
pathInset = inset * i;
pathW = width - i * inset * 2;
pathH = width - i * inset * 2;
// create the path
var path =
pathType == "rectangle"
? al.pathItems.rectangle(-pathInset, pathInset, pathW, pathH)
: al.pathItems.ellipse(-pathInset, pathInset, pathW, pathH);
// name path and set specs
path.name = "Path " + (i + 1);
path.move(cp, ElementPlacement.PLACEATBEGINNING);
path.evenodd = true;
path.fillColor = newColor;
path.stroked = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment