Skip to content

Instantly share code, notes, and snippets.

@tlinkner
Created January 11, 2017 20:52
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 tlinkner/ab5194dbaf82f42d9e3db8706ed9488b to your computer and use it in GitHub Desktop.
Save tlinkner/ab5194dbaf82f42d9e3db8706ed9488b to your computer and use it in GitHub Desktop.
This script is for Illustrator CC. It resizes objects to have the same diagonal dimension.
// BalanceDiagonal.jsx
// 2017 Todd Linkner
// License: none (public domain)
// v1.0
//
// This script is for Illustrator CC. It resizes objects to have the same diagonal dimension.
//
// Install to /Applications/Adobe Illustrator CC/en_US/Scripts/Mobile
// bring Illustrator into focus
#target illustrator
var activeDoc = app.activeDocument,
selection = activeDoc.selection;
if (activeDoc && selection.length == 1) {
var w = selection[0].width,
h = selection[0].height,
hypotenuse = Math.sqrt(Math.pow(w, 2) + Math.pow(h, 2)),
items = activeDoc.layers[0].pageItems
;
for (i = items.length - 1; i >= 0; i--) {
var w2 = items[i].width,
h2 = items[i].height,
// theta = atan(opposite/adjacent)
angle = Math.atan(h2/w2)
;
// adjacent = cos(angle) * hypotenuse
items[i].width = Math.cos(angle) * hypotenuse;
// opposite = sin(angle) * hypotenuse
items[i].height = Math.sin(angle) * hypotenuse;
}
alert("Done.");
} else {
alert("Error: Missing active document or selection or a single object. Try again.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment