Skip to main content
Legend
April 22, 2019
Answered

Is there description of the numeric 'layerKind' indexes that are available through AM?

  • April 22, 2019
  • 2 replies
  • 3611 views

Hello! For the script to work, I need to analyze the names of the layers of the document. I get a list of all the layers through AM, then in a loop I sort them in array according to desc.getInteger (stringIDToTypeID ('layerKind')). The problem is that layerKind comes in the form of a numeric index and, in case I need to match a specific type of layer in AM with the type of a layer in DOM,  and I need to understand what index it means. Is there description of the numeric 'layerKind' indexes that are available through AM?

This topic has been closed for replies.
Correct answer r-bin

Taken from "C:/Program Files/Adobe/Adobe Photoshop CC 2018/Required/CopyCSSToClipboard.jsx"

// SheetKind definitions from USheet.h

const kAnySheet             = 0;

const kPixelSheet           = 1;

const kAdjustmentSheet      = 2;

const kTextSheet            = 3;

const kVectorSheet          = 4;

const kSmartObjectSheet     = 5;

const kVideoSheet           = 6;

const kLayerGroupSheet      = 7;

const k3DSheet              = 8;

const kGradientSheet        = 9;

const kPatternSheet         = 10;

const kSolidColorSheet      = 11;

const kBackgroundSheet      = 12;

const kHiddenSectionBounder = 13;

2 replies

Known Participant
August 12, 2019

Thanks

r-binCorrect answer
Legend
April 22, 2019

Taken from "C:/Program Files/Adobe/Adobe Photoshop CC 2018/Required/CopyCSSToClipboard.jsx"

// SheetKind definitions from USheet.h

const kAnySheet             = 0;

const kPixelSheet           = 1;

const kAdjustmentSheet      = 2;

const kTextSheet            = 3;

const kVectorSheet          = 4;

const kSmartObjectSheet     = 5;

const kVideoSheet           = 6;

const kLayerGroupSheet      = 7;

const k3DSheet              = 8;

const kGradientSheet        = 9;

const kPatternSheet         = 10;

const kSolidColorSheet      = 11;

const kBackgroundSheet      = 12;

const kHiddenSectionBounder = 13;

Known Participant
April 19, 2023

Do you know when this index was established? This is giving me issues in CS5. It works fine in CC, but when checking the backward compatibility like explained in my other post you helped me with I am getting some errors. 

 

Stephen Marsh
Community Expert
Community Expert
October 21, 2024

var layer = app.activeDocument.activeLayer;

// Determine the fill type (solid color, gradient, or pattern)
switch (layer.kind) {
case LayerKind.SOLIDFILL:
alert("The layer fill type is a SOLID color fill.");
break;
case LayerKind.GRADIENTFILL:
try {
// Use Action Descriptor to access gradient properties
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); // Target current layer
var desc = executeActionGet(ref);
// The gradient fill is under 'adjustment' property of the descriptor
var gradientFill = desc.getList(stringIDToTypeID('adjustment')).getObjectValue(0);
// Now retrieve the gradient type
var gradientType = gradientFill.getEnumerationValue(stringIDToTypeID("type"));
// Check for Linear or Radial gradient
if (gradientType == charIDToTypeID('Lnr ')) {
alert("The gradient type is LINEAR.");
} else if (gradientType == charIDToTypeID('Rdl ')) {
alert("The gradient type is RADIAL.");
} else {
alert("The gradient type is UNKNOWN.");
}
} catch (e) {
alert("Error in retrieving gradient fill information: " + e.message);
}
break;
case LayerKind.PATTERNFILL:
alert("The layer fill type is a PATTERN color fill.");
break;
default:
alert("The layer fill type has UNKNOWN fill.");


@high voltaged53703767 

 

Hey, that’s great!

 

I have extended your code to additionally include Angle, Reflected and Diamond (P.S. Your copy and paste missed a closing } bracket)

 

/*
Get Gradient Type.jsx
by Istvan_HighVoltage
https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-there-description-of-the-numeric-layerkind-indexes-that-are-available-through-am/td-p/10461752
*/

var layer = app.activeDocument.activeLayer;
// Determine the fill type (solid color, gradient, or pattern)
switch (layer.kind) {
    case LayerKind.SOLIDFILL:
        alert("The layer fill type is a SOLID color fill.");
        break;
    case LayerKind.GRADIENTFILL:
        try {
            // Use Action Descriptor to access gradient properties
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); // Target current layer
            var desc = executeActionGet(ref);
            // The gradient fill is under 'adjustment' property of the descriptor
            var gradientFill = desc.getList(stringIDToTypeID('adjustment')).getObjectValue(0);
            // Now retrieve the gradient type
            var gradientType = gradientFill.getEnumerationValue(stringIDToTypeID("type"));
            // Check for Linear or Radial gradient
            if (gradientType == charIDToTypeID('Lnr ')) {
                alert("The gradient type is LINEAR.");
            } else if (gradientType == charIDToTypeID('Rdl ')) {
                alert("The gradient type is RADIAL.");
            } else if (gradientType == charIDToTypeID('Angl')) {
                alert("The gradient type is ANGLE.");
            } else if (gradientType == charIDToTypeID('Rflc')) {
                alert("The gradient type is REFLECTED.");
            } else if (gradientType == charIDToTypeID('Dmnd')) {
                alert("The gradient type is DIAMOND.");
            }
            else {
                alert("The gradient type is UNKNOWN.");
            }
        } catch (e) {
            alert("Error in retrieving gradient fill information: " + e.message);
        }
        break;
    case LayerKind.PATTERNFILL:
        alert("The layer fill type is a PATTERN color fill.");
        break;
    default:
        alert("The layer fill type has UNKNOWN fill.");
}