Copy link to clipboard
Copied
I have quite a bit projects which contain a layer group by the name "Cover" and I want to rename it to "Cover Group" using this action.
But into "Cover" layer group there is a layer with the same name. So when my action starts, instead of find and rename the layer group "Cover", renames the layer "Cover"!!!
Any idea how can I define my action so to rename the layer group and not the layer?
You may need to script that, Script can use logic to process layersets and also test the object kind that is targeted or currently active. Layers can be addressed by the Layer ID which is unique where Name need not be unique. You can have many layers with the name cover, In Actions it best to navigate layers relatively then by name. Even that can be a problem for only visible layer will be targeted relatively. If you want to do complex processing Scripting is your best option.
Copy link to clipboard
Copied
You may need to script that, Script can use logic to process layersets and also test the object kind that is targeted or currently active. Layers can be addressed by the Layer ID which is unique where Name need not be unique. You can have many layers with the name cover, In Actions it best to navigate layers relatively then by name. Even that can be a problem for only visible layer will be targeted relatively. If you want to do complex processing Scripting is your best option.
Copy link to clipboard
Copied
As JJ mentioned, scripts are the way to go. Even with scripts, if you have two or more layers with the same name, you can run into issues. You can use a command to get a layer by name, but it will only find the first instance of that name. Unless you know the exact ID of the layer, you might need to loop through the layers to detect a match. In your case, checking to see it the layer is an art layer or a layer set.
Copy link to clipboard
Copied
#target photoshop
s2t = stringIDToTypeID;
renameGroup('Cover', 'Cover Group')
function renameGroup(from, to) {
(ref = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfLayers'));
ref.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var len = executeActionGet(ref).getInteger(p);
for (var i = 1; i <= len; i++) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerSection'));
r.putIndex(s2t('layer'), i);
if (typeIDToStringID(executeActionGet(r).getEnumerationValue(p)) == 'layerSectionEnd') continue;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerKind'));
r.putIndex(s2t('layer'), i);
if (executeActionGet(r).getInteger(p) != 7) continue;
(ref = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
ref.putIndex(s2t('layer'), i);
if (executeActionGet(ref).getString(p).match(new RegExp(from, 'i'))) {
(r = new ActionReference()).putIndex(s2t('layer'), i);
(d = new ActionDescriptor()).putReference(s2t('null'), r);
(d1 = new ActionDescriptor()).putString(s2t('name'), to);
d.putObject(s2t('to'), s2t('layer'), d1);
executeAction(s2t('set'), d, DialogModes.NO);
}
}
}
Copy link to clipboard
Copied
doesn't seem to work ...
(ps2020)
Copy link to clipboard
Copied
Maybe we need to select group before renaming? I have no 20 version to check
#target photoshop
s2t = stringIDToTypeID;
renameGroup('Cover', 'Cover Group')
function renameGroup(from, to) {
(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 (typeIDToStringID(executeActionGet(r).getEnumerationValue(p)) == 'layerSectionEnd') continue;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerKind'));
r.putIndex(s2t('layer'), i);
if (executeActionGet(r).getInteger(p) != 7) continue;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
r.putIndex(s2t('layer'), i);
if (executeActionGet(r).getString(p).match(new RegExp(from, 'i'))) {
(r = new ActionReference()).putIndex(s2t("layer"), i);
(d = new ActionDescriptor()).putReference(s2t("null"), r);
executeAction(s2t("select"), d, DialogModes.NO);
(r = new ActionReference()).putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
(d = new ActionDescriptor()).putReference(s2t('null'), r);
(d1 = new ActionDescriptor()).putString(s2t('name'), to);
d.putObject(s2t('to'), s2t('layer'), d1);
executeAction(s2t('set'), d, DialogModes.NO);
}
}
}
Copy link to clipboard
Copied
According to given scenario you may use below script:
aD.activeLayer = (aD = activeDocument).layerSets.getByName('Cover')
or directly rename it (so without selecting):
activeDocument.layerSets.getByName('Cover').name += ' Group'
Copy link to clipboard
Copied
select layer Cover
rename CoverTmp
select layer Cover
rename CoverGroup
select layer CoverTmp
rename Cover
Copy link to clipboard
Copied
Loll, I had earlier to suggest exaclty same workaround, but then thought, nah, too nasty 😉
Copy link to clipboard
Copied
what is "nah" ? : )
Copy link to clipboard
Copied
That's english slang - antitype for yeah 😄
Copy link to clipboard
Copied
In Russian, the meaning is about the same, but this is an obscene vocabulary 😄
Copy link to clipboard
Copied
Yea, not obscene in the U.S., at least, as far as I know. But then there are a lot of crazies getting upset at all sorts of our words.
Copy link to clipboard
Copied
Oh yeah, I recently found on this forum this problem the US deals with (how ever it seems for many it's positive). That was few days ago in InDesign community where one commonly used M-word was banned from 2022 edition.
I am happy to see not all world goes crazy, and r-bin with jazz-y smiled after I unconsciously used a word of that type. Although we have access to global environment via internet, perhpas the reason we are not affected by that trend, is we live in countries on other part of planet, where laugh is more valued than wrath.
Copy link to clipboard
Copied
If the relative position of the layers in all documents is the same, then you can use the commands for moving along the layers palette to select the desired element, for example:
Copy link to clipboard
Copied
Another idea stolen from my mind! How were you able to take it over so fast?
Actually I was close. I missed out collapsing grups and it doesn't work for invisible layers.
Copy link to clipboard
Copied
There can be a problem Targeting layers relatively in Actions. Select Front, Back, Forward, Backward layer. Only select visible layer you can not select layers that have the visibility turned off. So which layer be be select can change. There is a dependency on the layers visibility state.