Do you want to align objects via script, but just don't know how to go about it? Or if you do know how, do you find yourself constantly drawing little pictures to try and remember the correct equation to align 2 objects in the correct way (do i divide this one by 2? do i add these values or subtract them?)? Do you find that since you don't write the logic every day, you always yourself getting it wrong all the time and being frustrated while you keep trying different configurations of the equation until it works? Do you wish there was a super easy to use library that gave you easy access to named alignment functions that mimic the behavior of the UI's alignment tools (including key object alignment)?
Wish no more! Here are those alignment functions, free for you to use or adapt or whatever you want. Simply feed any of these functions a "key object" (any pageItem), and an array of pageItems you want to align to the key object.
And here's a demo video:
Edit: here's a fixed demo. In the first demo, i had forgotten a function call in the test function that caused improper "bottom right" alignment.
future plans...? distribute functions. 😃
If you find these useful.. Please consider buying me a cup of coffee at the link in the js file. 😃
If you'd like to extend this functionality in some way that better fits your workflow, contact me at email@example.com
If you've wanted this kind of library for some other functionality, but aren't sure how to go about it... Let me know.
All the best, and happy coding.
You're not really setting any object as a true "key object" like you do in the UI. It's just that whatever item you pass to the functions as the first argument, all other items in the second argument array will be aligned relative to that object.
You needn't do anything in the UI at all. You could create some items via script, then pass them as arguments to be aligned.
Thanks for the public library.
Fortunately that function is just a combination of the align right and align bottom functions and we know those both work from the other examples.
Just rushing for some reason, I guess.
awesome! thanks for sharing William!
You guys have all given me so much over the last 5 years... It's only right to try and return the favor. And if I can get some experience writing code that will be used by others instead of just for myself, I'll be better suited to working on a team in the future.
Getting public comment and criticism is also invaluable as well, but almost all the code I've ever written has been seen only by me or a client that doesn't know how to code.
To that end, I'll be writing more and more stuff for free use and posting it around here. Hopefully that'll end up growing into a large library of useful stuff that will make scripting illustrator more accessible to everyone. And as mentioned, it'll give ample opportunity for the bright minds around here to tear my code apart and ask me, "why on earth would you do it THAT way?" or "did you ever consider [edge case(s)]??" ultimately resulting in a community driven project designed to fill some holes in the API.
I have done some experiments this year as a basis for a blog that goes over some item-moving principles, I'll have to dig those up and do some screenshots and make the blog to post on here. Hope to get to it before a few weeks.
Sweet! Thanks for sharing.