Copy link to clipboard
Copied
I have a layer that has "Dust & Scratches" effect applied.
The layer has several Time Remap keyframes and I am applying this code on that Time Remap property like this ():
effect("Dust & Scratches")("Threshold") = 60;
But I got error saying "Cannot apply value" - does anyone know why?
It sounds like you want the equivalent of hold keyframes, to turn the effect on/off each time it passes a Time Remap keyframe?
These kinds of things are a bit fiddly with expressions but here's something that may be close to what you want. You'd apply it to the Threshold property of the Dust & Scratches effect:
a = timeRemap;
nearestKey = a.nearestKey(time).index;
if (time < a.key(nearestKey).time) nearestKey --;
if (nearestKey/2 != Math.round(nearestKey/2)) 0;
else 255;
Translation for the above would
...Copy link to clipboard
Copied
effect("Dust & Scratches")("Threshold").setValue(60);
see
http://docs.aenhancers.com/properties/property/#property-setvalue
Copy link to clipboard
Copied
Thanx but nope: I did try that myself before asking this question - similar result ("effect()().setValue is not a function").
Copy link to clipboard
Copied
I'm guessing here but is this actually an expression, not a script? (you posted in the Scripting forum not the Expression forum) You said you applied it to the Time Remap property, so this is an expression on a Time Remap property?
You can't set the value of one property using an expression on another (i.e. your expression on Time Remap can't tell Dust & Scratches what value to be) but you can read the value of another property to use on the one the expression is applied to. Not sure why you'd want to use the Threshold property of Dust & Scratches to drive a Time Remap property though. Maybe you could explain what you're trying to do.
Copy link to clipboard
Copied
My, bad - YO ARE RIGHT! I am actually talking about expression, sorry guys, ah... 😞
+ no, you got me wrong (or did I just express myself wrong again?): I am driving Threshold value of the effect on every keyframe of timeRemap, I am too lazy doing it manually all the time and this way it would be pretty universal: just copy it to another such layer and that's it, no fiddling around.
So now as you correct me (this is EXPRESSION, not script) how come I cannot change value of another property when I can do that like a breeze by using that @ button?
All I want is to change the Threshold value of "Dust & Scratches" effects so it would basically switch it off: the layer it is applied on is morphing layer where I morph between several faces but in the process of the morph there are artefacts this effect help me to get rid off them but it makes the graphic being blurred, so I only want to apply on every other keyframe (k1 = 0, k2 = 255, k3 = 0, k4 = 255 etc
Copy link to clipboard
Copied
It sounds like you want the equivalent of hold keyframes, to turn the effect on/off each time it passes a Time Remap keyframe?
These kinds of things are a bit fiddly with expressions but here's something that may be close to what you want. You'd apply it to the Threshold property of the Dust & Scratches effect:
a = timeRemap;
nearestKey = a.nearestKey(time).index;
if (time < a.key(nearestKey).time) nearestKey --;
if (nearestKey/2 != Math.round(nearestKey/2)) 0;
else 255;
Translation for the above would be:
grab the timeRemap property for this layer
find the index of the nearest remap keyframe at the current time (expressions are recalculated on each individual frame)
if the current time is earlier than the nearest keyframe, reduce 'nearestKey' by 1 so we're always considering the keyframe before the current time.
if keyframe is an odd value (i.e. if value divided by 2 doesn't equal the same result rounded down) make the value 0, otherwise make it 255.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Beautiful - works exactly as I wanted, thank you so much (signed your answer as the correct one)! 😉
You may post this same as solution to my second post I gave you link to - just reverse the 0/255 values (as I need to be it off at the start)
May I ask what tht INDEX at the end of nearestKey(time).index do? I did not find about it anywhere? Does it gives you actual index of the closest kayframe or what?
Copy link to clipboard
Copied
Index is the number of the keyframe in order from first to last, so first keyframe's index is 1, second is 2 etc.
So this is how I'm working out if a keyframe is an even or odd one in terms of order.
You can both find the index of a keyframe you've found some other way (i.e. what is the index of the nearest key at the current time) or you can find a keyframe using its index (i.e. what is the time of the first keyframe / the keyframe with an index of 1 );
Copy link to clipboard
Copied
Thank you for the explanation, I knew what the INDEX s such is, I just did not know that I can call INDEX right after the nearestKey()
Copy link to clipboard
Copied
If you consider that things like comps, layers, properties and keyframes are objects...i.e. they don't have a simple numerical value, they are a 'thing'.
So once you have an object you can access any property or method available for that kind of object. With a property (i.e. timeRemap) you can look in the expression menu (the > in a circle next to the pickwhip) and under Property you'll see all the things you can access from a property object.
A few things in that Property menu will return a keyframe object (i.e. key(index) or nearestKey(time), at which point you can access the things in the Key menu (value, time or index).
So that's how you get to:
timeRemap.nearestKey(time).index or access the nearest TimeRemap key at the current time and tell me the index for that keyframe.