Skip to content

Instantly share code, notes, and snippets.

@maximilliangeorge
Forked from animoplex/MarkerSyncExpression.jsx
Last active April 9, 2020 15:04
Show Gist options
  • Save maximilliangeorge/8994c77c6625b7214cf4359b9b92c75d to your computer and use it in GitHub Desktop.
Save maximilliangeorge/8994c77c6625b7214cf4359b9b92c75d to your computer and use it in GitHub Desktop.
Marker Sync - After Effects Expression by Animoplex
// MARKER SYNC
//
// Allows you to trigger playback of precomp segments using markers.
// This allows you to change timings without diving into precomps and makes it easier to reason about your project file.
//
// 1. Create a precomp A with a layer called "Controller"
// 2. Add named markers to the timeline within Controller.
// 3. In the parent comp, enable Time Remapping for the precomp A
//
// Modified expression based on Dan Ebbert's Marker Sync Expression
// Original Version: http://www.motionscript.com/design-guide/marker-sync.html
// Full Tutorial: https://www.youtube.com/watch?v=B_3XS2-VWOM&t=698s
src = comp(name).layer("Controller");
n = 0;
if (marker.numKeys > 0) {
n = marker.nearestKey(time).index;
if (marker.key(n).time > time) {
n--;
}
}
if (n == 0) {
0
} else {
m = marker.key(n);
myComment = m.comment;
t = time - m.time;
try {
mark = src.marker.key(myComment);
if (src.marker.numKeys > mark.index) {
tMax = src.marker.key(mark.index + 1).time - mark.time;
} else {
tMax = src.outPoint - mark.time;
}
t = Math.min(t, tMax);
mark.time + t;
}catch (err) {
0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment