Group selection
hello, how to select only groups, without selecting layers?
needed for action😰
Or is there some kind of sorting? to show only groups
["Actions" tag added by moderator]
hello, how to select only groups, without selecting layers?
needed for action😰
Or is there some kind of sorting? to show only groups
["Actions" tag added by moderator]
Maybe it's because I don't use artboards? they are not in the hierarchy ... I'm not strong in photoshop, I'm hearing about artboards for the first time)
Maybe it's because I don't use artboards? they are not in the hierarchy ... I'm not strong in photoshop, I'm hearing about artboards for the first time)
By @Max_red_cat
If there are no artrboards in the file, the script should have informed you of that fact:

That would be the problem, you previously wrote about an artboard and the screenshot had the top of the layer structure truncated where the artboard would have been visible:
for example, a small fragment of the layer hierarchy, the selected group is the final version
there is only one artboard, groups can be nested within groups, but the main thing is to rename the older groups, nested ones can remain unchanged
prefix is always static "[merge]"
So, you only wish to prefix all top-level layer groups? If so, try this version:
/*
Add prefix to top-level groups.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/group-selection/td-p/13624612
v1.0 - 4th March 2023, Stephen Marsh
*/
#target photoshop
function main() {
// Capture the initial layer visibility and layer selection
var currentLayersState = getLayersVisiblity();
// Set the layer groups variable
var theLayerSets = activeDocument.layerSets;
// Forward loop over the layer groups
for (var i = 0; i < theLayerSets.length; i++) {
// Check if the layer is a group and a top level group
// if (theLayerSets[i].typename === "LayerSet" && theLayerSets[i].parent == activeDocument) {
if (theLayerSets[i].typename === "LayerSet") {
theLayerSets[i].name = "[merged] " + theLayerSets[i].name;
}
}
// Restore the initial layer visibility and selection
setLayersVisiblity(currentLayersState);
}
activeDocument.suspendHistory('Add prefix to top-level groups...', 'main()');
//// Functions ////
function getLayersVisiblity() {
// by jazz-y
var s2t = stringIDToTypeID,
t2s = typeIDToStringID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var targetLayers = executeActionGet(r).getList(p),
seletion = [],
visiblity = {};
for (var i = 0; i < targetLayers.count; i++) seletion.push(targetLayers.getReference(i).getIdentifier());
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfLayers'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var len = executeActionGet(r).getInteger(p);
for (var i = 1; i <= len; i++) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerSection'));
r.putIndex(s2t('layer'), i);
if (t2s(executeActionGet(r).getEnumerationValue(p)) == 'layerSectionEnd') continue;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerID'));
r.putIndex(s2t('layer'), i);
var id = executeActionGet(r).getInteger(p);
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('visible'));
r.putIndex(s2t('layer'), i);
var visible = executeActionGet(r).getBoolean(p);
visiblity[id] = visible;
}
return {
selection: seletion,
visiblity: visiblity
};
}
function setLayersVisiblity(layersStateObject) {
// by jazz-y
var s2t = stringIDToTypeID;
for (var a in layersStateObject.visiblity) {
makeVisible = layersStateObject.visiblity[a] ? "show" : "hide";
(r = new ActionReference()).putIdentifier(s2t('layer'), a);
(d = new ActionDescriptor()).putReference(s2t('target'), r);
executeAction(s2t(makeVisible), d, DialogModes.NO);
}
if (layersStateObject.selection.length) {
var r = new ActionReference();
for (var i = 0; i < layersStateObject.selection.length; i++)
r.putIdentifier(s2t("layer"), layersStateObject.selection[i]);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
d.putBoolean(s2t("makeVisible"), false);
executeAction(s2t("select"), d, DialogModes.NO);
} else {
(r = new ActionReference()).putEnumerated(s2t("layer"), s2t('ordinal'), s2t('targetEnum'));
(d = new ActionDescriptor()).putReference(s2t('target'), r);
executeAction(s2t('selectNoLayers'), d, DialogModes.NO);
}
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.