PyQGIS Script to run in QGIS to find the total length of lines in a layer in ellipsoid meters

Job ID: 33506256

Budget: £20 – £250 GBP

I have a script that loops every feature, gets the length, adds it up and outputs the total length in meters for each layer.

Problem is, this outputs in planimetric and I need in ellipsoidal.

I don't want to add any fields to the attribute table I need it to pull the length using Python.

I need someone to rewrite my script attached or write a new one to solve this issue.

Thanks
Tom