Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Test for method existance?

  • Test for method existance?

    Posted by Deriksmith on September 27, 2007 at 1:02 am

    I have an expression that refers to thisComp.activeCamera.

    The problem is that I don’t always necessarily HAVE a camera in this scene. (Humor me and assume I’m still in the process of rigging/duplicating this comp, and have a good reason to be deleting the active camera for awhile before putting a new one in.)

    Problem- when there is no active camera in the comp- the expression promptly errors out and deactivates itself. I’ve tried my standard javascript approach: if (thisComp.activeCamera) but rather than evaluating as undefined/null/false, the expression throws an error the moment it even TESTS thisComp.activeCamera for existence… because it does not exist.

    Is there a method for testing for something’s existence? In ANOTHER example- I’d like to be able to put in an expression that says “Do this only if the comp has a layer called ‘Fred’.” But calling thisComp.layer(“fred”) errors out and kills the script (unless there actually is a layer named Fred, natch.)

    Ideas?

    Dan Ebberts replied 18 years, 10 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    September 27, 2007 at 2:41 am

    I think try/catch is what you’re looking for. Example:

    try{
    C = thisComp.activeCamera;
    }catch(err){
    C = null;
    }

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy