Copy link to clipboard
Copied
I'm trying to record an Action that's aligning a layer. However, no step is recorded when I change the alignment baseline from "layer" to "canvas". So, the recorded Action will be very brittle, depending on the future current value of this application setting.
Is there a way to persist the layer alignment baseline setting?
I couldn't find a corresponding ExtendScript property for this setting, too. So I cannot create a corresponding script, either. Which property would I need to set in JavaScript?
Your answers are appreciated.
What if you first did a Select > All?
Copy link to clipboard
Copied
What if you first did a Select > All?
Copy link to clipboard
Copied
Excellent answer! Thank you 🙂
Copy link to clipboard
Copied
Thank you. Happy to help.
Copy link to clipboard
Copied
Just to add to @Michael Bullo suggestion, record Select > All as action step, selection must be active when playing action, action will align to selection not to canvas.
Copy link to clipboard
Copied
Here is align to canvas via scripting listener:
https://gist.github.com/MarshySwamp/618a08fd04c4f3ed0027f6926b6d9d62
// Align Active Layer to Canvas.jsx
/*
ADSLefts = Align Left
ADSRights = Align Right
ADSCentersH = Align Centre Horizontal
ADSTops = Align Top
ADSBottoms = Align Bottom
ADSCentersV = Align Centre Vertical
null = insert "null" to quickly disable one of the two alignment options
*/
alignToCanvas(true, "ADSLefts");
alignToCanvas(true, "ADSTops");
function alignToCanvas(alignToCanvas, alignValue) {
app.activeDocument.selection.selectAll();
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( s2t( "null" ), reference );
descriptor.putEnumerated( s2t( "using" ), s2t( "alignDistributeSelector" ), s2t( alignValue ));
descriptor.putBoolean( s2t( "alignToCanvas" ), alignToCanvas );
executeAction( s2t( "align" ), descriptor, DialogModes.NO );
app.activeDocument.selection.deselect();
}
Copy link to clipboard
Copied
And align to select all:
https://gist.github.com/MarshySwamp/df372e342ac87854ffe08e79cbdbcbb5
// Align Active Layer to Select All.jsx
/*
//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
*/
//www.ps-scripts.com/viewtopic.php?f=66&t=7036&p=35273&hilit=align+layer#p35273
align2SelectAll('AdCH'); align2SelectAll('AdCV'); //Change as required
function align2SelectAll(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();
}
Copy link to clipboard
Copied
Very nice! 👍
Thanks for sharing!
Copy link to clipboard
Copied
I was curious, so I recorded two actions, one aligning to canvas and one aligning to selection. I converted each to a script using xtools.
The only notable difference in the code is:
desc1.putBoolean(sTID("alignToCanvas"), true);
vs.
desc1.putBoolean(sTID("alignToCanvas"), false);
However, when the action is played, both versions will error and fail if there is no selection before running the action. Align to canvas shouldn't require a selection, as the scripts posted above demonstrate. Therefore I can only conclude that this is a long-standing bug in the action playback, as the boolean for canvas appears to be recorded into the action, even if not visible in the action panel interface.
Copy link to clipboard
Copied
Will you report a bug?
Copy link to clipboard
Copied
Done:
Please add your (up)vote if you can reproduce this issue.