Copy link to clipboard
Copied
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?
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 kSolidColor
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Will not work in CS5 and CS6. Also the property "hasBackgroundLayer" is not available (there will be an error). These properties are available with some version of CC, I can't tell which one.
Copy link to clipboard
Copied
Oh boy, this is gonna be a long process for me haha. Thanks for the help!
Copy link to clipboard
Copied
If the AM code is a problem for the older versions, perhaps you could use standard DOM code:
// http://creativetuts.com/photoshop-script-determine-layer-kind/
// Photoshop Script
// "Determine Layer Kind"
// Script by Mehmet Åžensoy
#target photoshop
app.bringToFront();
var doc = app.activeDocument;
var layer = doc.activeLayer;// Save selected layer to variable:
function determinelayerkind(layer) {
if (layer.kind == LayerKind.TEXT) { layerkind = "Text Layer"; return layerkind; } // Text Layer
else if (layer.kind == LayerKind.SOLIDFILL) { layerkind = "Shape Layer"; return layerkind; } /* Shape Layer */
else if (layer.kind == LayerKind.BLACKANDWHITE) { layerkind = "Black and White adjustment layer"; return layerkind; } /* Black and White */
else if (layer.kind == LayerKind.BRIGHTNESSCONTRAST) { layerkind = "Brightness contrast adjustment layer"; return layerkind; } /* Brightness contrast adjustment layer */
else if (layer.kind == LayerKind.CHANNELMIXER) { layerkind = "Channel mixer adjustment layer"; return layerkind; } /* Channel mixer adjustment layer */
else if (layer.kind == LayerKind.COLORBALANCE) { layerkind = "Color balance adjustment layer"; return layerkind; } /* Color balance adjustment layer */
else if (layer.kind == LayerKind.CURVES) { layerkind = "Curves adjustment layer"; return layerkind; } /* Curves adjustment layer */
else if (layer.kind == LayerKind.EXPOSURE) { layerkind = "Exposure layer"; return layerkind; } /* Exposure layer */
else if (layer.kind == LayerKind.GRADIENTFILL) { layerkind = "Gradient fill"; return layerkind; } /* Gradient fill */
else if (layer.kind == LayerKind.GRADIENTMAP) { layerkind = "Gradient map adjustment layer"; return layerkind; } /* Gradient map adjustment layer */
else if (layer.kind == LayerKind.HUESATURATION) { layerkind = "Hue saturation adjustment layer"; return layerkind; } /* Hue saturation adjustment layer */
else if (layer.kind == LayerKind.INVERSION) { layerkind = "Invert adjustment layer"; return layerkind; } /* Invert adjustment layer */
else if (layer.kind == LayerKind.LAYER3D) { layerkind = "3D layer"; return layerkind; } /* 3D layer */
else if (layer.kind == LayerKind.LEVELS) { layerkind = "Levels adjustment layer"; return layerkind; } /* Levels adjustment layer */
else if (layer.kind == LayerKind.NORMAL) { layerkind = "Normal layer"; return layerkind; } /* Normal Layer */
else if (layer.kind == LayerKind.PATTERNFILL) { layerkind = "Pattern fill layer"; return layerkind; } /* Pattern fill layer */
else if (layer.kind == LayerKind.PHOTOFILTER) { layerkind = "Photo filter layer"; return layerkind; } /* Photo filter layer */
else if (layer.kind == LayerKind.POSTERIZE) { layerkind = "Posterize adjustment layer"; return layerkind; } /* Posterize adjustment layer */
else if (layer.kind == LayerKind.SELECTIVECOLOR) { layerkind = "Selective color adjustment layer."; return layerkind; } /* Selective color adjustment layer */
else if (layer.kind == LayerKind.SMARTOBJECT) { layerkind = "Smart object layer"; return layerkind; } /* Smart object layer */
else if (layer.kind == LayerKind.THRESHOLD) { layerkind = "Threshold adjustment layer"; return layerkind; } /* Threshold adjustment layer */
else if (layer.kind == LayerKind.VIBRANCE) { layerkind = "Vibrance layer"; return layerkind; } /* Vibrance layer */
else if (layer.kind == LayerKind.VIDEO) { layerkind = "Video layer"; return layerkind; } /* Video layer */
else if (app.activeDocument.activeLayer.typename === "LayerSet" && app.activeDocument.activeLayer.layers.length === 0) { layerkind = "Layer Set"; return layerkind; } /* Layer Set */
else if (app.activeDocument.activeLayer.typename === "LayerSet" && app.activeDocument.activeLayer.layers.length > 0) { layerkind = "Layer Set + Content"; return layerkind; } /* Layer Set - Must have content */
}
alert("Current Layer is a " + determinelayerkind(layer));
Copy link to clipboard
Copied
Hi guys.
Can someone help me?
I want to determine if a gradient is linear or radial gradient?
Is it possible with PS scripting jsx?
Copy link to clipboard
Copied
Looking at the SL output:
var idtype = stringIDToTypeID( "type" );
var idgradientType = stringIDToTypeID( "gradientType" );
var idlinear = stringIDToTypeID( "linear" );
desc182.putEnumerated( idtype, idgradientType, idlinear );
And:
var idtype = stringIDToTypeID( "type" );
var idgradientType = stringIDToTypeID( "gradientType" );
var idradial = stringIDToTypeID( "radial" );
desc193.putEnumerated( idtype, idgradientType, idradial );
Unfortunately my AM code knowledge only allows me to adapt existing code, so it's a matter of finding code that tests for other layer properties and adapting it via trial and error.
Hopefully somebody with more than a superficial understanding of AM code can help.
Copy link to clipboard
Copied
thanks a lot , in the meantime, I found another solution that works
Copy link to clipboard
Copied
thanks a lot , in the meantime, I found another solution that works
By @high voltaged53703767
Please do share!
Copy link to clipboard
Copied
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.");
Copy link to clipboard
Copied
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.");
}
Copy link to clipboard
Copied
Hi Stephen.
Thats great.
Do you have any idea how to reach the stroke information?
I know, the basic stroke attributes are stored in the executeActionGet(r).getString(stringIDToTypeID('layerSVGdata'), but the advanced attributes, like stroke-linecap or dash, and the others are not.
When I use Layer menu / copy SVG, than there are all these informations, and I figured how to reach that menu with JSX, but it is impossible to reach the clipboard via jsx scripting.
So I need to find another solution, but I did not yet.
Do you or anyone has any idea?
Thanks a lot
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks
Find more inspiration, events, and resources on the new Adobe Community
Explore Now