The kind of color fill layers and shape layers is the same
The kind of color fill layers and shape layers is the same. How can I distinguish between a color fill layer and a shape layer using JSX?
The following checks if the layer's kind is a shape and the path is greater than or equal to 1, which would make it a shape layer. However, there’s a flaw: if a PSD file has paths with more than 1, a color fill layer might also be incorrectly identified as a shape layer.
(function() {
// Get the currently active document
var doc = app.activeDocument;
var subPathsLength = 0;
try {
subPathsLength = doc.pathItems[0].subPathItems.length
// Read the number of paths
} catch (error) {}
// Get the currently selected layer
var selectedLayer = doc.activeLayer;
// Check if the selected layer is a shape layer
if (selectedLayer.kind == LayerKind.SOLIDFILL && subPathsLength >= 1) {
alert("The selected layer is a shape layer.");
} else {
alert("The selected layer is not a shape layer.");
}
}());
