Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Detect if layer was deleted via scripting

  • Detect if layer was deleted via scripting

    Posted by Malte Hillebrand on January 4, 2020 at 2:02 pm

    Is there any way to detect if a layer was deleted by the user and then execute some code?

    If I delete a layer stored as a variable and then call the variable it tells me that the object is invalid. Comparing it to a null doesn’t return true or false as it’s not really an object (?).
    Not sure which way to go to react to a user deleting a certain layer, created by and crucial to my script.

    Andrei Popa replied 6 years, 8 months ago 2 Members · 1 Reply
  • 1 Reply
  • Andrei Popa

    January 4, 2020 at 3:26 pm

    You could use a try/catch block. Something like this


    try {
    var a = app.project.item(1).layer("Shape Layer 1").name;
    alert(a);
    }catch(e){
    alert("You shouldn't delete the layer");
    }

    Another way would be to compare the layer to a null. You must do this before trying to access any of the property. If you do (app.project.item(1).layer(“Shape Layer 1”) == null) you get a true value if the layer does not exist. However, if you try to access any property of a layer that does not exist, you get an error. Something like this doesn’t work (app.project.item(1).layer(“Shape Layer 1”) == null)

    Andrei
    My Envato portfolio.

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