ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Detect if layer was deleted via scripting

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Malte Hillebrand
Detect if layer was deleted via scripting
on Jan 4, 2020 at 2:02:12 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.


Return to posts index

Andrei Popa
Re: Detect if layer was deleted via scripting
on Jan 4, 2020 at 3:26:27 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.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]