Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Library for aligning objects via script.

Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

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. 

 

https://github.com/wdjsdev/public_illustrator_scripts/blob/master/alignment_functions.js

 

And here's a demo video:

https://photos.app.goo.gl/JunYSy2368DbRhHL8

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.

https://photos.app.goo.gl/jYHqHXMdLRDHSsNXA

 

functions include:

  • alignObjectsToCenter effectively does a veritcal align center and horizontal align center.
  • vAlignTop aligns the top edge of all objects to the top edge of the key object
  • vAlignCenter aligns the vertical center of all objects to the vertical center of key object
  • vAlignBottom aligns all bottom edges to key object
  • hAlignLeft aligns all left edges to left edge of key object
  • hAlignCenter aligns all horizontal center points to horizontal center point of key object
  • hAlignRight aligns all right edges to right edge of key object

 

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 illustrator.dev.pro@gmail.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.

William

TOPICS
How to, Scripting, SDK, Tools

Views

306

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

@DilliamWowling 

Nice work and thanks for sharing with all of us.

Thank you. 😊 

One question: Do we need to make an object as a key object manually?

Best regards

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Got it. 

Thanks for the public library.

Best regards

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Hi @DilliamWowling 

nice work.

😉

 

(Just a side note: bottom right doesn't work properly in your video.)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Haha. Doh!

 

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. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

fixed. 😃

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

awesome! thanks for sharing William!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 27, 2021 Mar 27, 2021

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

LATEST

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 27, 2021 Mar 27, 2021

Copy link to clipboard

Copied

Sweet! Thanks for sharing.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines