• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Scripting - Get layer when in a group

Explorer ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

So i know i can use the below to get a layer

 

var layerName = "Text BG";
app.activeDocument.activeLayer = layers[layerName];

 

This works fine when the layer isn't within a group, but if it is I get an error

Error 1302: No such element

Line: 53 ->  app.activeDocument.activeLayer = layers[layerName];

 

The layer is within a group called Text Group, how do i go about getting the group correctly?

TOPICS
Actions and scripting

Views

508

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
LEGEND ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

layers is undefined

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

Layers is fine, as i said it works fine if the layer isn't in a group.

 

Layers is defined using

var layers = app.activeDocument.layers;

earlier in the script

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

 

with(activeDocument)
	activeLayer = layerSets['Text Group'].artLayers['Text Bg']

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

@Desbrina I believe that @Kukurykus has provided one possible solution which you can mark as the correct answer. 

 

In my journey of learning scripting, I have collected various useful snippets. The last example in this link uses layer index:

https://gist.github.com/MarshySwamp/229a0676666a44cdaa007da1cfddc0b7

 

The following is basically the same as the reply from Kukurykus with a slightly different syntax, swapping the layer index numbers in the GitHub Gist example above for names. 

 

activeDocument.activeLayer = activeDocument.layerSets["Text Group"].layers["Text BG"];

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

LATEST

Yes, as the others have mentioned, you need to select the group to get the layer within it. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines