Assuming you are using a shape layer and a straight path with two points, you could try this on the ‘dash’ property:
n = 10 ; // number of dashes
shp = content("Shape 1").content("Path 1").path ;
p1 = shp.points(time)[0] ;
p2 = shp.points(time)[1] ;
d = length( p1, p2 )
d / n / 2
If its curved, the math would be much more difficult.
If you are OK with dots on a line versus dashes, you can use the Audio Waveform effect on a layer… Set the Display Options to ‘Digital’, the Audio Samples to the number of dots you want, the Thickness and colors as needed. The create a mask on that layer (curved or straight) and, in the Audio Waveform settings, set the Path property to that mask. Then you can animate the mask as needed and the line of dots will follow it and maintain a consistent number of dots.