Skip to content

Instantly share code, notes, and snippets.

@MarshySwamp
Last active December 15, 2022 23:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarshySwamp/ef345ef3dec60a843465347ee6fcae2f to your computer and use it in GitHub Desktop.
Save MarshySwamp/ef345ef3dec60a843465347ee6fcae2f to your computer and use it in GitHub Desktop.
Report on the active layer name, layer itemIndex & layer id value
/////////// ACTIVE LAYER INSPECTOR v1.8, 6th January 2022 ///////////
/////////////// Displays info about the current layer ///////////////
/* https://community.adobe.com/t5/photoshop/could-you-select-all-layers-sequentially/m-p/11741392 */
/* Name = Not unique */
/* itemIndex = Changes with layer addition/removal, Background layer index starts at 0 - no Background starts at 1 */
/* layer.id = Unique, Static */
// Bounds:
// + - - - - - - - [1] - - - - - - - +
// | |
// | |
// [0] [2]
// | |
// | |
// + - - - - - - - [3] - - - - - - - +
#target photoshop
try {
var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
var docLayer = doc.activeLayer;
var layerName = docLayer.name;
var itemIndex = getActiveLayerIndex();
var layerID = docLayer.id;
var typeName = docLayer.typename;
var Kind = docLayer.kind;
var bgLayer = docLayer.isBackgroundLayer;
var Parent = docLayer.parent;
var clipMask = docLayer.grouped;
/* https://community.adobe.com/t5/photoshop/find-out-the-size-and-position-of-an-object-in-a-layer/td-p/12057799 */
var bounds = activeDocument.activeLayer.bounds;
alert('ACTIVE LAYER INSPECTOR - v1.8' + '\r' + 'Layer Name: ' + layerName + '\r' + 'Layer Item Index #: ' + itemIndex + '\r' + 'Layer ID #: ' + layerID + '\r' + 'Layer Type: ' + typeName + '\r' + 'Layer Kind: ' + Kind + '\r' + 'Parent: ' + Parent + '\r' + 'isBackgroundLayer: ' + bgLayer + '\r' + 'Grouped: ' + clipMask +'\n' + 'Layer Bounds -' + '\r' + 'X1 - [0]: ' + app.activeDocument.activeLayer.bounds[0] + '\r' + 'Y1 - [1]: ' + app.activeDocument.activeLayer.bounds[1] + '\r' + 'X2 - [2]: ' + app.activeDocument.activeLayer.bounds[2] + '\r' + 'Y2 - [3]: ' + app.activeDocument.activeLayer.bounds[3] + '\r' + 'Width: ' + (app.activeDocument.activeLayer.bounds[2] - app.activeDocument.activeLayer.bounds[0]) + '\r' + 'Height: ' + (app.activeDocument.activeLayer.bounds[3] - app.activeDocument.activeLayer.bounds[1]));
app.preferences.rulerUnits = savedRuler;
function getActiveLayerIndex() {
/* https://github.com/Paul-Riggott/PS-Scripts/blob/master/getLayersetLayerIDs.jsx */
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
try {
activeDocument.backgroundLayer;
return executeActionGet(ref).getInteger(charIDToTypeID("ItmI")) - 1;
} catch (e) {
return executeActionGet(ref).getInteger(charIDToTypeID("ItmI"));
}
};
}
catch (e) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment