How to Change "Align to" option with script?
Copy link to clipboard
Copied
hi everyone,
is there a way to change "align to" option with script?
i want to write code for align object with my script to Artboard or to selections....
but the Align to option the Align Palette not chaneged.
Thank for answers...
Explore related tutorials & articles
Copy link to clipboard
Copied
Hi,
May be following link will be helpful to you
For Selection or key objectss
For artboard
Not tested myself but can give you an idea. It may not able to achieve what you want to see on UI, but ofcourse end result will be same.
Copy link to clipboard
Copied
Hi.
Thanks a lot for your response.
I wire the script for aligning,
the problem is that this method work well in the case that selected one object or one group,
but when I select an cliped mask object or group that has clip mask and etc dont work corectly,
use of align panel of Illustrator dont this problem. you can use align for objec or group that inside of many clip mask or etc.
my solution is that use an Action for the align object, and call the Action from a UI dialog and command button.
every thing is ok. but new problem is that i can not change the "Align to" option from my dialog....
thanks again.
best regards.
Copy link to clipboard
Copied
Here's a script I wrote that matches selected objects on multiple attributes, alignment being one of those. The script also accounts for groups, clipping masks, groups inside of clipping mask, etc. You can read more here.
Download Script:
https://github.com/joshbduncan/adobe-scripts/blob/main/MatchObjects.jsx
Copy link to clipboard
Copied
Thank a lot.
it is work very well.
Copy link to clipboard
Copied
I stole your "getVisibleBounds" function because that's good stuff. thanks. 😃
one thing to watch out for though, is that it's possible to have a compoundPathItem with no child pathItems which would cause a runtime error.
I don't know if there are more ways to get this situation, but i've seen some compound paths that are created from multiple groupItems. in this case, the compoundPathItem.pathItems[0] portion will fail.
Copy link to clipboard
Copied
Hey, good catch on the empty objects! I'm not sure I was able to replicate your exact situation but I did find a bunch of gotchas with the function.
I have just pushed an update so if you want to checkout my latest PR and see if it works better for you that would be awesome. It's definitely not as nice and clean as before but it seemed to catch some weird edge cases in my test Illustrator file (attached).
I also created the script DrawVisibleBounds.jsx for testing the function. It's a simple and fast way to see if you are getting the correct bounds.
Thanks for your help!
Copy link to clipboard
Copied
Sample file attachment didn't work... Here's a Dropbox link to download it if you want to test it for yourself.
Copy link to clipboard
Copied
To replicate the issue i mentioned, draw 4 squares in a 2x2 grid. group the left column. then group the right column. then select both groups and create a compound path. Now isolate that compound path with a script and query the pathItems property. You'll find the collection is empty because the only things inside are two groupItems.
Copy link to clipboard
Copied
Ah, gotcha... The updated version seems to work on this case too. I'm sure there are so many other weird cases that'll break it, just glad I could fix a few this go-round. Thanks again for the heads up!
Copy link to clipboard
Copied
Gah, i'm a goof. first time i looked at your code, i found an issue. then when you fixed it, and i went back looking at it, i didn't see the issue anymore. then you merged to main and i saw the issue again. haha. I made a pull request with the proposed fixes. The issue was inside your clip mask condition. If the object was a clip group, you checked to see whether the top level element was a compound path, then if it was you tried to access the pathItems[0] element. this is where you'll get the runtime error if you have a compound clipping path like i described yesterday.
here's an edited version of your hot_mess.ai file which contains the kind of artwork i'm talking about.
https://drive.google.com/file/d/1VD3bu7tNlycPSqpEOZw3qmN5u3mYcvxz/view?usp=sharing

