Maya python script that can flat jagged lines,please help

I was making a maya python script which intends to turn jagged lines(or faces) into straight lines(or flatten faces).
Just like the picture below:

I was thinking that I can relatively scale all selected components in x and z axes,so the result will align to y axis.

This is my code:

import pymel.core as pm

#sel =
pv = pm.manipScaleContext('Scale',q=True,p=True)

But it doesn’t work at all.
I can get the pivot of the selected components.It seems the scaleComponents didn’t work as expected.I also tried the scale funtion,same result.The jagged lines are still there.

Is there any mistake in my code?
Other solutions are also welcomed.

nevermind,I found the solution,
I need to scale down the second value in the coordinate to align edge to y axis,pm.scale(1,0,1,p=pv),
which is very confusing.

explanation is much appreciated.