ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

if/else exists expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
if/else exists expression
on Oct 12, 2017 at 10:19:12 am

for (var i = 1; i <= myComp.numLayers; i++){
var myComp = app.project.activeItem;
var nNum = myComp.layer(i).effect("Name")("Slider").value;
var name = myObject[nNum].name;
myComp.layer(i).name = name;
};


I'm having a little problem with my script.

My name layers will never be the same, but the ones I want to effect will all have the slider "Name"...Again value will differ. The number is for my JSON reference...

Now...The above expression in my script works fine, if I don't have any other layers that have no slider or a different slider.

I don't have a way to reference the content of the slider, so I need it to say "if I exist change me else continue" I've tried a few things with no success.

I'm sure I've read someone with a similar situation, but I've read about 50 different forums and can't find anything. Any ideas?


Return to posts index

Dan Ebberts
Re: if/else exists expression
on Oct 12, 2017 at 1:03:16 pm

One way might be to use try/catch:


try{
// try to do something here
}catch(err){
continue; // end up here if it don't work
}



Dan



Return to posts index

Scott McGee
Re: if/else exists expression
on Oct 12, 2017 at 1:30:40 pm

I am a moron....

I even tried a try/catch, but did it every wrong way possible, even when you posted that I did it wrong initially again and realised I have to put it in the loop for it too work, because I want to reference 4 categories I've been trying to put the try outside of it.

That is working sport on now.

Thank you for putting that, I would have gone around in circles otherwise.

for (var i = 1; i <= myComp.numLayers; i++){

try{
var nNum = myComp.layer(i).effect("Name")("Slider").value;
var name = myObject[nNum].name;
myComp.layer(i).name = name;
}catch(err){
continue;
}
};

for (var i = 1; i <= myComp.numLayers; i++){

try{
var lNum = myComp.layer(i).effect("Location")("Slider").value;
var location = myObject[lNum].location;
myComp.layer(i).name = location;
}catch(err){
continue;
}
};


Unless you can think of a tidier way for this...I only have to do it 4 times and it's only a find and replace. Last year I typed 480 text layers out, I'm doing it again this year and giving myself RSI hahahaha.

Appreciate that.


Return to posts index

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