Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

How to Change "Align to" option with script?

Explorer ,
Sep 23, 2021 Sep 23, 2021

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...

 

TOPICS
Scripting
812
Translate
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 Expert ,
Sep 23, 2021 Sep 23, 2021

Hi,

May be following link will be helpful to you

 

For Selection or key objectss

https://community.adobe.com/t5/illustrator-discussions/library-for-aligning-objects-via-script/m-p/1...

 

For artboard

https://community.adobe.com/t5/illustrator-discussions/script-to-align-selected-objects-to-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.

Best regards
Translate
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
Explorer ,
Sep 24, 2021 Sep 24, 2021

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.

 

Translate
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
Community Expert ,
Oct 01, 2021 Oct 01, 2021

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

Translate
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
Explorer ,
Oct 09, 2021 Oct 09, 2021

Thank a lot.

it is work very well.

Translate
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
Community Expert ,
Oct 11, 2021 Oct 11, 2021

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.

Translate
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
Community Expert ,
Oct 13, 2021 Oct 13, 2021

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!

 

 

Translate
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
Community Expert ,
Oct 13, 2021 Oct 13, 2021

Sample file attachment didn't work... Here's a Dropbox link to download it if you want to test it for yourself.

Translate
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
Community Expert ,
Oct 13, 2021 Oct 13, 2021

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.

Translate
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
Community Expert ,
Oct 13, 2021 Oct 13, 2021

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!

Translate
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
Community Expert ,
Oct 14, 2021 Oct 14, 2021
LATEST

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

Translate
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