Child Layers of a Duplicated Group

After duplicating a layer group, I want to be able to target the child text layers of the subsequent new group. And populate each text layer with new content. None of this seems as straight forward as it would be in Extendscript. What am I missing?

Thanks in advance.

  1. Duplicate Group (new group should be selected afterwards)
  2. Get target layer index
  3. Iterate over all layers by Index in reverse (starting from the groups index)
  4. Check for the layerKind property
  5. Populate Text
  6. Stop iteration when the layer property layerSection is “layerSectionEnd”

Note 1: If you have nested groups inside the group, you need to increase a counter for every “layerSectionStart” and decrease it for every “layerSectionEnd”, if it’s 0 then you’ve reached the end of the (outer) group.

Note 2: If you want to do this in 1 batchPlay call, you can’t get the index (step 2.) in between. Instead you could calculate beforehand how many layers the group has (steps 3-6) so that you know at which index the new group starts after the duplication.

1 Like

Thanks Simon. That helped me along quite a bit. As these text layers are named (and also only contain) an index, what method would you recommend if I want to use the text layer (ex: 1, or ex: 13) as the index of an array I have for actual text to populate it? Think… mail merge in PS haha.
Thanks for the help!

I didn’t quite get that part, could you try to explain this in other words?

Sorry about the confusion Simon, I’ll try to clarify with an image also.
I duplicate an initial layer group which contains text layers populated with a number (incidentally they are named with the same number way also).

For this use case, I want to know what number is populated in the given text layer (either by contents, or its layer name), so that I can replace the number in the layer marked “1”, to item 1 of a JSON array.

I hope that helps to clarify a bit more. I’m guessing mapping would be useful here also?

I don’t think you need any mapping, you can just access the value at the given index using the numeric string:

const arr = ['a','b','c']
const third = arr['2'] // -> c

which works equally fine as arr[2]

1 Like

Thanks for your help on this Simon. I got it all squared away.