Skip to main content
KlausKi
Inspiring
March 20, 2022
Answered

How can I record layer alignment baseline?

  • March 20, 2022
  • 4 replies
  • 1022 views

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.

This topic has been closed for replies.
Correct answer Michael Bullo

What if you first did a Select > All?

4 replies

Stephen Marsh
Community Expert
March 22, 2022

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.

Kukurykus
Brainiac
March 22, 2022

Will you report a bug?

Stephen Marsh
Community Expert
March 22, 2022
Stephen Marsh
Community Expert
March 21, 2022

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();
}

 

Stephen Marsh
Community Expert
March 21, 2022

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();

}
KlausKi
KlausKiAuthor
Inspiring
March 21, 2022

Very nice! 👍

 

Thanks for sharing!

Bojan Živković11378569
Community Expert
March 21, 2022

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.

Michael Bullo
Michael BulloCorrect answer
Community Expert
March 20, 2022

What if you first did a Select > All?

KlausKi
KlausKiAuthor
Inspiring
March 21, 2022

Excellent answer! Thank you 🙂

Michael Bullo
Community Expert
March 21, 2022

Thank you. Happy to help.