Copy link to clipboard
Copied
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.");
}
}());
That script looks kinda familiar (now at v1.8) :]
I have recently created a new script which processes all layers in the file (not just the active layer) and writes the data to a CSV file:
...
Earlier discussions which might prove useful:
Copy link to clipboard
Copied
That script looks kinda familiar (now at v1.8) :]
I have recently created a new script which processes all layers in the file (not just the active layer) and writes the data to a CSV file:
Layer Name | Visibility | Type | Kind (DOM) | Kind (AM) |
Triangle | TRUE | ArtLayer | LayerKind.SHAPELAYER | kVectorSheet |
Color Fill | TRUE | ArtLayer | LayerKind.SOLIDFILL | kSolidColorSheet |
The active layer inspector script could be updated to use this better codebase...
It's similar to Layer Groups, Artboards and Frame layers all being reported by DOM code as a layerSet – it takes extra AM code to qualify the differences:
Copy link to clipboard
Copied
Thank you, I extracted this code from it. It works fine in Photoshop CC and above versions, but not in CS6 and below. Thanks again!
(function() {
if (isShapeLayerAM(app.activeDocument.activeLayer)) {
alert("The selected layer is a shape layer.");
} else {
alert("The selected layer is not a shape layer.");
}
function isShapeLayerAM(layer) {
try {
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), layer.id);
var layerDesc = executeActionGet(ref);
return layerDesc.getInteger(stringIDToTypeID("layerKind")) === 4;
} catch (e) {
return false;
}
}
}());
Copy link to clipboard
Copied
Thank you, I extracted this code from it. It works fine in Photoshop CC and above versions, but not in CS6 and below. Thanks again!
By @w30290083o9nn
Yes, the wonders and joys of AM code, it can be version specific and various keys may be different or might not exist in earlier versions.
Copy link to clipboard
Copied
Earlier discussions which might prove useful:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now