this is a bit easier to do with a mask path and the stroke effect, purely because you need to get the square layer to follow the path, and you can easily copy/paste a mask path into the position property and then go from there…
but you can still use trim paths, you’ll need to create a mask path that is the same as the shape layer’s path that has trim paths on it.
then you’ll copy/paste the mask path into the position property of the black square.
then you can use an expression like this to link the position of the black square to the trim paths property of the other shape layer:
completion = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Trim Paths 1").end;
valueAtTime(linear(completion,0,100,0,key(numKeys).time))
the shape should follow the trim paths end property.
since your square is offset from the stroke, you may want to apply the expression to a null and parent the square to the null, to make it easier to position it correctly.
also, you’ll want to set the null to auto orient along path.
Kevin Camp
Art Director
KCPQ, KZJO & KRCW