Skip to main content
Inspiring
February 6, 2021
Answered

Use width of a layer as input in recorded action

  • February 6, 2021
  • 2 replies
  • 740 views

I want to record an action where i use the width of one layer (variable a) as an input in the action - so that I can select that another layer uses that variable a to place the layer on the canvas (I want X of layer 2 to be equal to variable a).

Is this possible?

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

No it is not possible with an action, however, it is possible with a script.

2 replies

rob day
Community Expert
Community Expert
February 9, 2021

Open the two documents with the left scan as the front document and try this script:

 

 

#target photoshop
preferences.rulerUnits = Units.PIXELS;
var d1 = app.documents[0];
var d2 = app.documents[1];

var sprd = d2.duplicate(d1.name + "-" + d2.name,true)    
sprd.resizeCanvas(d1.width+d2.width, d2.height, AnchorPosition.TOPRIGHT);

app.activeDocument=d1;
d1.layers[0].duplicate (sprd);

 

 

A pair of single layer docs with the left page active. The two docs have different pixel widths:

 

 

after running the script:

 

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
February 6, 2021

No it is not possible with an action, however, it is possible with a script.

Inspiring
February 6, 2021

Ok, thanks! Then I'll have to decide whether it's worth figuring how to write a script or just do it manually 🙂

 

Stephen Marsh
Community Expert
Community Expert
February 7, 2021

Yes, that is always the case, life is full of trade offs, Photoshop is no different.

 

will there always be the same quantity of layers in the same positions with the same names? 

 

If you can post a cropped screenshot of your layers panel and perhaps an image of two layers as a before and after that may assist anybody willing to help code this. If you have an action sharing that would help, even if it can't do 100% of what you require.