Skip to main content
Community Expert
August 2, 2020
Answered

Expression question - check for an effect on a layer above

  • August 2, 2020
  • 1 reply
  • 320 views

I have searched high and wide and can't seem to find an answer. Maybe I'm just tired. I need to check to see if there is a slider with a specific name on the layer above the current layer and then return a default value if the slider does not exist. I thought this approach would work, but it throws an error.

 

if(thisComp.layer(index - 1).effect("Line Spacing")("Slider") == null)
	lineGap = 0
else
	lineGap = thisComp.layer(index - 1).effect("Line Spacing")("Slider");

 

There must be a way to check to see if there is an effect added to another layer.  If I add a slider named Line Spacing to the layer above and change the == from null to 100 then the conditional statement works, the lineGap matches the slider value until it reaches 100 then drops to zero.

 

If anyone knows the answer it's Dan_Ebberts. I hope I'm missing something simple.

This topic has been closed for replies.
Correct answer Dan Ebberts

This should work:

 

try{
lineGap = thisComp.layer(index - 1).effect("Line Spacing")("Slider");
}catch(e){
lineGap = 0;
}

 

Dan

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
August 2, 2020

This should work:

 

try{
lineGap = thisComp.layer(index - 1).effect("Line Spacing")("Slider");
}catch(e){
lineGap = 0;
}

 

Dan

Community Expert
August 3, 2020

Perfect Dan. Thanks. It's now in my expression bible...