Page 1 of 1

Can I check if a layer has an effect?

Posted: August 23rd, 2011, 9:27 am
by thehardme
Hi to all!

I am tweaking Ebberts' collission detector for a project. There are going to be a lot of layers in the comp, and some of them will work as obstacles for a collision. I want to make some of these layers obstacles, and one object to collide should detect them. So the ideal would be

if (L.effect("IsObject")(Checkbox))

to check every layer in every frame before going to the collision check. But if a layer doesn't have an effect called IsObject, the expression won't work. Is there a way to detect if a layer has an effect with particular name so I don't have to create this effect on every layer?

Regards

Re: Can I check if a layer has an effect?

Posted: August 23rd, 2011, 11:31 am
by Dan Ebberts
Here's an example that should count the layers with the checkbox:

Code: Select all

n = 0;
for (i = 1; i <= thisComp.numLayers; i++){
  if (i == index) continue; // skip myself
  try{
    thisComp.layer(i).effect("isObject")("Checkbox");
  }catch (e){
    continue;
  }
  n++;
}
n
Dan

Re: Can I check if a layer has an effect?

Posted: August 23rd, 2011, 1:08 pm
by thehardme
Thanks a lot, Dan, it's now working beatifully.