Skip to main content
Inspiring
April 14, 2021
Answered

How to rapidly align one layer to another by center, or simply, align by center?

  • April 14, 2021
  • 4 replies
  • 1769 views

1. How can I simply align one layer to another by each layer's center?

There is currently:

  • Align by Horizontal Centers
  • Align by Vertical Centers

But, how do you just Align by Center? That way you don't have to select the options twice.

 

2. What is the fastest way to align one layer to another by their centers? The only method I've found so far is to drag the layer to the other one and hope it automatically finds and aligns by center, but I can't be 100% sure it works with this approach, because I have to eyeball it.

 

 

This topic has been closed for replies.
Correct answer Stephen Marsh

You can record an action that plays both align steps from a single run, or a script that does similar (a few more steps may be necessary). Both can be run from keyboard shortcuts or the actions panel.

 

There are also smart guides and the move tool.

4 replies

jane-e
Community Expert
Community Expert
August 1, 2021

 


@hen5FD8 wrote:

2. What is the fastest way to align one layer to another by their centers?

 


The only way I can conceive of dragging one layer onto another is if they are in different files, otherwise you would be using the layers panel.

 

To center a layer as you move it from one document into another, hold down the Shift key. Is that what you are looking for?

 

~ Jane

leahbraaten28
Participant
July 31, 2021

It would be nice if they created this function as a simple button. I use a recorded action like other have suggested but I dislike having to do that. I'm someone who likes to have fewer things recorded as history states. I know that with this particular action it's only two history states so undoing/redoing isn't much. However for something that is so simple like this it seems silly to not have a single button.

Stephen Marsh
Community Expert
Community Expert
August 1, 2021

It would require a script, rather than an action, if you wish to have a single history state.

 

Select two or more layers, or one layer and a select all then run the following script to align centers with a single history state:

 

/* 

Align Centers.jsx

www.ps-scripts.com/viewtopic.php?f=66&t=7036&p=35273&hilit=align+layer#p35273

www.macscripter.net/viewtopic.php?id=38890

AdLf = Align Left
AdRg = Align Right
AdCH = Align Centre Horizontal
AdTp = Align Top
AdBt = Align Bottom
AdCV = Align Centre Vertical
*/

#target photoshop

function alignLayers() {

    //Change as required
    alignSelectedLayers('AdCH');
    alignSelectedLayers('AdCV'); 

    function alignSelectedLayers(method) {
        //app.activeDocument.selection.selectAll();
        var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
        desc.putReference(charIDToTypeID("null"), ref);
        desc.putEnumerated(charIDToTypeID("Usng"), charIDToTypeID("ADSt"), charIDToTypeID(method));
        try {
            executeAction(charIDToTypeID("Algn"), desc, DialogModes.NO);
        } catch (e) {}
        //app.activeDocument.selection.deselect();
    }
}
app.activeDocument.suspendHistory("Align Centers", "alignLayers()");

 

Or perhaps you  would prefer to have the script play an action set and action so that you have more flexibility while still retaining a single history step:

 

#target photoshop

function alignLayers() {
var actionName = "My Align Centers Action"; // Action to run
var actionSet = "My Align Set"; // Action set to run
app.doAction(actionName,actionSet);
}
app.activeDocument.suspendHistory("Align Centers", "alignLayers()");

 

A custom keyboard shortcut can be assigned to an installed script or you could record an installed or browsed script into an action.

 

Downloading and Installing Adobe Scripts

c.pfaffenbichler
Community Expert
Community Expert
April 14, 2021

To use one Layer’s position for alignment you can load its transparency as a Selection (cmd-click its icon in the Layers Panel). 

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
April 14, 2021

You can record an action that plays both align steps from a single run, or a script that does similar (a few more steps may be necessary). Both can be run from keyboard shortcuts or the actions panel.

 

There are also smart guides and the move tool.

hen5FD8Author
Inspiring
April 14, 2021

Thanks.

I created an action that does both Align to Horizontal & Vertical Center. Then I assigned a function hotkey to it.

How to assign a hotkey to action: How do you assign a hotkey to a recorded action?

 

Then I assigned CTRL SHIFT Q ... and.... CTRL SHIFT 1 .... to align by horizontal center... and the other for vertical center. (Edit--> Keyboard Shortcuts--> )

hen5FD8Author
Inspiring
April 14, 2021

How do you assign a hotkey to a recorded action?