Skip to main content
Participating Frequently
April 30, 2025
Answered

How to Skip Last Layer in "For Each Layer" Block to Avoid Error? Automation Blocks

  • April 30, 2025
  • 1 reply
  • 392 views

Hi everyone,

I'm using the "For Each Layer" block in my script. What I’m trying to do is:

  • Get the current layer's position.

  • Add +100 to the position.

  • Set this value to the next layer.

Everything works fine except for the last layer. For example, if I have 10 layers, all 10 positions are set correctly, but I get this error:

 

execution result: could not find object with path '11': layer 11 does not exist

 

Because the script tries to access layer 11, which doesn't exist, it throws an error and stops the script.

I tried using index-based logic to avoid the last layer, but variables don't seem to work properly inside the "For Each Layer" block.

Has anyone solved this issue? How can I skip the last layer in a "For Each Layer" loop to avoid this error?

Thanks in advance!

Correct answer Mathias Moehl

You could for example retrieve the list of layers and then remove the last entry from that list before looping over them.

 

Here is an example where I alert the names of all layers of the active comp except the last one

(block code attached)

 

 

1 reply

Mathias Moehl
Community Expert
Mathias MoehlCommunity ExpertCorrect answer
Community Expert
April 30, 2025

You could for example retrieve the list of layers and then remove the last entry from that list before looping over them.

 

Here is an example where I alert the names of all layers of the active comp except the last one

(block code attached)

 

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects