Skip to main content
S_3_R_0
Participant
March 30, 2019
Question

Enabling "Align To Key Object" Via Script

  • March 30, 2019
  • 1 reply
  • 971 views

Hey there,

Is it possible to enable Align To Key Object via script or being able to align to a key object when 2 or more objects are selected? If this is possible, how can I do this preferably through JavaScript?

Thank you!

This topic has been closed for replies.

1 reply

Silly-V
Legend
March 30, 2019

Unfortunately you have to do so manually via scripting, which can be as simple as creating a function which changes the .top/.left properties of a pageItem object (or using the .translate() function) to accomplish your desired translation.

Likewise it's possible to use actions play-back via script to play an align action recorded from the Align panel - however there's the problem of not being able to control align to artboard vs selection via script. Thus if the user chooses a different option, it would fail some of the time.

And of course related to that is an even worse problem that there's no way to ascertain the key object via scripting either.

However a panel or dialog-series could be built to have the user "select" the key item either in document or dialog UI somehow, to replicate the effect of a user isolating some art as the key object.

If you are able to institute the convention that the 2nd item in the selection or the 1st item is always the key object then your job will be much clearer as you'll only need to regard the 1st of all the above paragraphs!

S_3_R_0
S_3_R_0Author
Participant
March 30, 2019

Thank you for the response, I really do appreciate it. Unfortunately, I don't think I quite understand what you're trying to say regarding the function which changes the .top/.left properties of a pageItem object. Unless I just need to re-read your response a little more to better understand.

Basically, I have quite a few template files with a singular object on it. I want to center align a pasted object with the template object into one of the template files. I found out I could complete this task by sending it down a layer so that the template object is the top layer and then enabling align to key object (which makes the template object the key object when both are selected without reselecting). And then I'm able to easily center align the pasted object to the template object.

Sorry if I'm not quite getting all of this, I'm just trying to wrap my head around how this would all work out.

Silly-V
Legend
March 30, 2019

I do understand better now too. I didn't necessarily know or take into account that the top object becomes the 'key' when that option is selected in Align panel, but the issue is the same: there doesn't appear to be a way to select this alignment preference via script at run-time.