Skip to main content
Participating Frequently
November 16, 2013
Question

script to align selected objects to artboard

  • November 16, 2013
  • 2 replies
  • 12377 views

Hello, I was wondering if anyone had a simple solution to aligning selected items to the artboard. I was going to create an action but then realized it would be more convenient for me to include it in my script file....I have a script to align objects with each other but they dont align to the artboard. Any suggestions?

2 replies

Participating Frequently
November 19, 2013

Bump!

pixxxelschubser
Community Expert
Community Expert
November 17, 2013

Hi volocitygraphics,

I think there isn't a simple solution for all possibilities.

But you can select one item and run this (selected item will be centered):

// AlignSelectedItem2Artboard.jsx

// ab CS5

// http://forums.adobe.com/thread/1336506?tstart=0

// (title: script to align selected objects to artboard)

// one selected item will be centered

// regards pixxxelschubser

var aDoc = app.activeDocument;

app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

var abIdx = aDoc.artboards.getActiveArtboardIndex();

var actAbBds = aDoc.artboards[abIdx].artboardRect;

var obj2move = aDoc.selection[0];

obj2move.position = new Array ((actAbBds[2]-actAbBds[0])/2 - obj2move.width/2, (actAbBds[3]-actAbBds[1])/2  + obj2move.height/2);

This is a variant. Another way is e.g. to align the artboard rectangle to your item.

Have fun

Participating Frequently
November 17, 2013

Hello, thanks for replying! Yes, this works for only one selected item. If I had many selected, it still only aligns the first one. I cannot figure out how to align all selected items to artboard either (other than manually)...you would think it would be more simple to align all selected if one can be aligned.....are there any other possibilities? Thanks again!

pixxxelschubser
Community Expert
Community Expert
November 17, 2013

.

I'm not sure what you really want.

Do you want to align the artboard around all selected items? Or do you want align all selected items in one artboard (how? each item or all items as one „group“ topleft, top, topright, left, center, right, bottomleft, bottom, bottomright???)

What for items do you have in your artboard? Only simple paths or grouped items or compound paths or clipped paths or all together or all together in grouped grouped grouped (deep nested) groups at many several toplevel layers?

Perhaps you can show two sceenshots: what you have (with visible opened layers palette) and a second one: what you want.

Regards

pixxxelschubser