Best commands for line best fit to wriggly line?

Hi,
V5
As I am going to be working with many sections through obj’s (meshes) and the surfaces of what were flat inevitably are giving slightly wriggly sections, I need to take what should be a straight line and make a straight one for it.

I need ‘best fit line though a wriggly line’.

I have done this in the past and expected to see a button I had made for it, but dont have one.

What would the coding be in the button ?

for V5

Would I be right in thinking first command is divide and have a decent number of points along the line, more the merrier in fact

then LineThroughPt.

is there a way maybe of asking for the number of points in the coding ?

also I need it to then select the points and group them before applying LineThroughPt.
makes selecting the points easier afterwards.

Cheers

Steve