1

I have a very large PS document with over 1100 layers. I have to arrange them in neat rows, but to accomplish that, I need to do some math to decide the best arrangement.

It would make the process much smoother, if it were readily possible to count the number of layers currently selected, making it easier to figure which layers to move, and where to move them, as they have to remain in their current order. I know how to see the number of total layers, but I can't seem to find a way to automatically count the number in a given selection.

I I've looked all over the software, so I'm afraid this just isn't possible, but I appreciate any feedback anyone can give me!

  • I don't think it's possible. – Scott Jan 30 '18 at 17:02
  • 1100...But why? This isn't possible, furthermore, why does it matter how many you have selected? – Ovaryraptor Jan 30 '18 at 17:04
  • Obviously its possible – joojaa Jan 30 '18 at 17:05
  • 1
    Not an answer, but a possible work-around: rename each layer with an appropriate prefix to represent your objective. Clunky, time consuming, laborious, etc. If a script could be created to accomplish this, all the better. – fred_dot_u Jan 30 '18 at 17:10
  • 1
    I'd highlight layers.. duplicate them to their own document, create a row of people. Repeat for each row. Then you have a file for each row, Then you can combine (as smart objects) the row photos into one file. The math is kind of simple.. determine how many people fit horizontally.. 30 people per row... 1100 people.. 37 rows, etc. At least then you've got files with 30-40 layers which is much more manageable. – Scott Jan 30 '18 at 17:12
2

Well you can use scripting, which is the way to go for this kind of stuff. Obviously I can not write the script for you because 1100 layers with some math to arrange in grid is not a actionable piece of description for a computer. Although I can guess what you want. I prefer not to since that will just lead to problems for me. So instead i will just push you on your way and hope you're smart enough to lift yourself up by the bootstraps with this info.

I'm not going to go terribly into deep detail how you use scripting, you open extendscript toolkit and paste this in. When your PS is open, you run it by hitting the triangle on top of extendscript toolkit window.

So first finding out how many layers are selected (using this trick):

#target photoshop
var selectedLayers = getSelectedLayers(app.activeDocument);
alert(selectedLayers.length)

function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

function newGroupFromLayers(doc) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putClass( sTID('layerSection') );
    desc.putReference( cTID('null'), ref );
    var lref = new ActionReference();
    lref.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
    desc.putReference( cTID('From'), lref);
    executeAction( cTID('Mk  '), desc, DialogModes.NO );
};

function undo() {
   executeAction(cTID("undo", undefined, DialogModes.NO));
};

function getSelectedLayers(doc) {
  var selLayers = [];
  newGroupFromLayers();

  var group = doc.activeLayer;
  var layers = group.layers;

  for (var i = 0; i < layers.length; i++) {
    selLayers.push(layers[i]);
  }

  undo();

  return selLayers;
};

Oh dear, Adobes scripting API is pretty useless. Ok now thet we know how many layers we have all we need to know is how to move a layer. Well that is pretty simple.

To move the topmost selected layer 10 units down from its curret position then do:

var pos = selectedLayers[0].bounds;
pos[1] = 10 - pos[1];
selectedLayers[0].translate(0 , 10);

From this follows that you can calculate a new position to all layers with something like:

var pos = selectedLayers[0].bounds;
pos[1] = 10 - pos[1];
selectedLayers[0].translate(0 , pos[1]);

From this follows that you can loop through each layer and do something for each position like so:

#target photoshop
var selectedLayers = getSelectedLayers(app.activeDocument);
alert(selectedLayers.length)


for( i = 0; i < selectedLayers.length; i++) {
    var pos = selectedLayers[0].bounds;
    pos[0] = yourmath - pos[0];
    pos[1] = yourmath - pos[1];
    selectedLayers[0].translate(pos[0] , pos[1]);
}



function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

function newGroupFromLayers(doc) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putClass( sTID('layerSection') );
    desc.putReference( cTID('null'), ref );
    var lref = new ActionReference();
    lref.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
    desc.putReference( cTID('From'), lref);
    executeAction( cTID('Mk  '), desc, DialogModes.NO );
};

function undo() {
   executeAction(cTID("undo", undefined, DialogModes.NO));
};

function getSelectedLayers(doc) {
  var selLayers = [];
  newGroupFromLayers();

  var group = doc.activeLayer;
  var layers = group.layers;

  for (var i = 0; i < layers.length; i++) {
    selLayers.push(layers[i]);
  }

  undo();

  return selLayers;
};

Remeber to replace: yourmath with something better.

Personal opinion: you would be much better off doing this in InDesign or Illustrator. Not only is the script cleaner but also the operating environment is cleaner. But yes you can use Photoshop if you are interested in masochism and are a firm believer that all objects are nails when your wielding a hammer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.