Skip to main content
Inspiring
October 27, 2022
Answered

How to align object vertically on the artboard via script?

  • October 27, 2022
  • 1 reply
  • 333 views

How to align object vertically on the artboard via script?

For example, there is a group

 

 

var smallCircleGroup = doc.groupItems.add();
// adding some objects to the group

 

 

Now I woud like to align the group vertically on the artboard as it would be done by `Vertical Align Center` Illustrator's command. Is there a script ecvivalent for the command to do that?

This topic has been closed for replies.
Correct answer femkeblanco
var ABR = app.activeDocument.artboards[0].artboardRect;
var ABVerticalCentre = (ABR[3] - ABR[1]) / 2;
var bounds = smallCircleGroup.controlBounds;
smallCircleGroup.top = ABVerticalCentre - ((bounds[3] - bounds[1]) / 2);

1 reply

femkeblanco
femkeblancoCorrect answer
Legend
October 27, 2022
var ABR = app.activeDocument.artboards[0].artboardRect;
var ABVerticalCentre = (ABR[3] - ABR[1]) / 2;
var bounds = smallCircleGroup.controlBounds;
smallCircleGroup.top = ABVerticalCentre - ((bounds[3] - bounds[1]) / 2);