Skip to main content
Participant
March 6, 2024
Question

Expressions: Making layermarkers using keyframes as triggers.

  • March 6, 2024
  • 4 replies
  • 626 views

Hi there, I've been having an issue all day and night with this expression. I'll post the code below.

var input = thisComp.layer("layerName").effect("Dropdown")("Menu");
var output = thisComp.layer("layerName2");
var timeStep = 0.04;
for (var t = input.startTime; t <= input.endTime; t += timeStep) {
    var dropdownValue = input.valueAtTime(t);
    output.addMarker(t, new MarkerValue(dropdownValue.toString()));
}

Let me clarify what I am trying to achieve here.
First of all, I added this expression to the Source Text property of a different text layer. It's supposed to act as a non visible layer just for code.

Right now I have some nested animations in precomps which can be triggered with markers and marker comments. But what I'm trying to achieve is a user friendly approach since I'm making a rig for someone else and manually writing markers isn't userfriendly enough. I have a control layer with several controls including the Dropdown effect. I want to animate this effect so that my output layer gets a new layer marker when there is a keyframe on the effect. The marker should output the value of the keyframe (the value of the dropdown menu).

If this would work, the animation would be triggered whenever the keyframe says so. 
However, it doesn't. I've been going over this using tutorials, reading ae scripting guide, chatting with ChatGPT, checking aenhancers.... But it won't work. For some reason, unknown to me, After Effects doesn't register certain functions which are used on all those platforms I researched. Some of those functions are '.keyTime()' or '.keyValue()' or 'new MarkerValue()'. But I'm no expert and I might just do something wrong.

So if there's an expert out there that can help me, that would be awesome.
This topic has been closed for replies.

4 replies

Mylenium
Legend
March 6, 2024

Based on your description it should be possible to just calculate the time difference between the markers and keyframes and then feed that into a valueAtTime() expression or whatever you are using. Of course hard to tell without knowing more of the specifics. Anyway, it seems the most crucial part is to uncouple the timing of the different markers and allow for a consistent calculation of the time difference, meaning it would probably be useful to have the pre-comp with evenly spaced m arkers and then determine the active segment based on the marker index to calculate the relative timing within the segment, rather than some complicated global time that may have been changed by shifting layers around, time-remapping or other stuff. The only real caveat would then be to not mess up the pre-comps' timing and leave them alone, only changing the timing of markers and keyframes in the parent comp.

 

Mylenium

Mylenium
Legend
March 6, 2024

What the others said. You can't create anything with expressions nor update a marker's data. It's read-only as far as expressions are concerned. Otherwise I'd say you are simply approaching things backwards and need to restructure your project. Why wouldn't you just have your markers in a top level comp and fetch them from within the nested sub-comps and then use some time logic to determine what needs to be triggered? Sure, not as simple as slapping a nearestMarker() on, but perfectly doable.

 

Mylenium

Participant
March 6, 2024

What kind of timelogic are you suggesting then? Since I have been mixing up scripting and expressions I just use markers. Right now I'm using fixed markers in my precomp and manually added markers in my main comp with the same comment as the fixed markers to trigger the animation of the precomp.

Legend
March 6, 2024

You can't add markers using an expression.

You need to create a script (JSX file)

Dan Ebberts
Community Expert
Community Expert
March 6, 2024

It looks like you're trying to combine two concepts (scripting and expressions), which are very different things. Expressions can't create anything (markers, for example), they can only modify the the value of the property containing the expression. Scripting can create things (markers, comps, layers, etc), but scripts don't automaticlly fire off based on events in the timeline (you generally have to run them manually). Based on that, I'm not sure what to suggest...

Participant
March 6, 2024

I had no idea I was mixing those two up. I'll have to approach the project differently. But thank you for clarifying this. I wouldn't have known otherwise.