Current Comp to Text Layer Source

Moderators: Disciple, zlovatt

Post Reply
Buchini
Posts: 3
Joined: October 5th, 2011, 7:30 am

Hey there,

I'm working on a school project with a classmate director.
I'm doing the visual effects and he is giving feedback.

To avoid confusion, I gave every single shot a separate comp.
I've used the expression from The Adobe After Effects site.

Code: Select all

source_footage_name = ""; 
  for (i = 1; i <= thisComp.numLayers; i++){ 
      if (i == index) continue; 
      my_layer = thisComp.layer(i); 
      if (! (my_layer.hasVideo && my_layer.active)) continue; 
      if (time >= my_layer.inPoint && time < my_layer.outPoint){ 
          try{ 
              source_footage_name = my_layer.source.name; 
          }catch(err1){ 
              source_footage_name = my_layer.name 
          } 
          break; 
      } 
  } 
  source_footage_name
On a text layer, but there are a few problems.

First, it is order sensitive, the first comp must be the lowest in timeline (so the highest layer number)
And the latest comp must be in the top (so the lowest layer number)
Is there a way to skip this variable?

Second, is there a way to give the expression a range.
Because I don't need the expression to name the adjustment layer on to, nor the source layer if there care no effects shot.

Fore example, layer 1 is a adjustment layer.
Layer 2 to 30 are effect comps
Layer 31 is the source layer.

Can the range be set from 2 tot 30, so that it will ignore the top and bottom layers?


I hope I make any sense to you.
If something is not clear, i'd be happy to explain more.

cheers,

Buchini
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

I don't understand the first part of your question. If you have multiple layers active at the same time, the one at the top of the layer stack is the one that will be visible. Don't you want the info for that one?

To restrict the range you just need to change:

for (i = 1; i <= thisComp.numLayers; i++){

to:

for (i = 2; i <= 30; i++){

or use variables, like this:

firstLayer = 2;
lastLayer = 30;
for (i = firstLayer; i <= lastLayer; i++){


Dan
Buchini
Posts: 3
Joined: October 5th, 2011, 7:30 am

Thank you for the quick reply, Dan!

It is more a sequence, multiple comps in one sequence, but I assumed that the layer order must be ascending and not descending.
I'm not sure if this is really necessary.



I've tried to add sliders to the expression for more flexibility:

Code: Select all

firstLayer = effect("First Layer")("Slider");
lastLayer = effect("Last Layer")("Slider");

 source_footage_name = ""; 
  for (i = firstLayer; i <= lastLayer; i++){
      if (i == index) continue; 
      my_layer = thisComp.layer(i); 
      if (! (my_layer.hasVideo && my_layer.active)) continue; 
      if (time >= my_layer.inPoint && time < my_layer.outPoint){ 
          try{ 
              source_footage_name = my_layer.source.name; 
          }catch(err1){ 
              source_footage_name = my_layer.name 
          } 
          break; 
      } 
  } 
  source_footage_name
But then the expression gives an error:

After Effects warning: Bad Argument: layer index 245128704 out of range
Expression Disabled


But when I just add numbers to the expression, like in your example with

Code: Select all

firstLayer = 3;
lastLayer = 15;
, The expression works like a charm.

Is there something I'm doing wrong, or is directly inserting the numbers into the expression the only way?
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

If I were doing it, I would restrict the slider values to legal layer indices like this:

Code: Select all

firstLayer = Math.min(Math.max(Math.round(effect("First Layer")("Slider")),1),thisComp.numLayers);
lastLayer = Math.min(Math.max(Math.round(effect("Last Layer")("Slider")),1),thisComp.numLayers);
Buchini
Posts: 3
Joined: October 5th, 2011, 7:30 am

thank you Dan, works perfectly!
SFR75
Posts: 17
Joined: April 3rd, 2007, 10:49 am

Nice! I couldn't figure out how to do it myself. It escaped my mind, that one can use loops in expressions :)... Thanks!
Post Reply