Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

 
Buchini
Topic Author
Posts: 3
Joined: Wed Oct 05, 2011 7:30 am

Current Comp to Text Layer Source

Thu Oct 20, 2011 3:13 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.
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: 319
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Re: Current Comp to Text Layer Source

Thu Oct 20, 2011 9:54 am

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
Topic Author
Posts: 3
Joined: Wed Oct 05, 2011 7:30 am

Re: Current Comp to Text Layer Source

Mon Oct 24, 2011 8:55 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:

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
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: 319
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Re: Current Comp to Text Layer Source

Mon Oct 24, 2011 10:04 am

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

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
Topic Author
Posts: 3
Joined: Wed Oct 05, 2011 7:30 am

Re: Current Comp to Text Layer Source

Tue Oct 25, 2011 2:21 am

thank you Dan, works perfectly!
 
SFR75
Posts: 17
Joined: Tue Apr 03, 2007 10:49 am

Re: Current Comp to Text Layer Source

Tue Dec 25, 2012 7:34 am

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

Who is online

Users browsing this forum: No registered users and 1 guest