Straighten vertical of conduit

I always seem to have the enoying problem of having conduiits that are supposed to be verical, be put in slightly off axis. This is can be a difficult issue to correct in Revit. So I want to write a script to do it for me. So my logic is this: find the x and y of the top and bottom points, see if they are equal, and then make them equal. However, although I seem to be able to do this, the more daunting task of actually implementing this into revit started to seep in. How then, since revit doesnt have parameters for these points do I adjust the model elements to match these new starting and endpoints? Thanks!

I think trying to straighten them automatically is too risky & unpredictable.

I’d suggest calculating the vector between start and end points, and using this to work out which are vertical (or orthogonal) and identify them e.g. setting a parameter, changing color etc

In the below example, I compare the conduit vector to the vector of the nearest major axis, and set a parameter accordingly. A view filter changes the color (green=orthogonal)

The sin() is there because depending on the direction of the conduit, an orthogonal conduit may be calculated as either either 180 or zero degrees
With the way Revit displays units, I have had to add a ‘fudge factor’- conduits which snapped to be orthogonal may report a angle of 179.999999999 degrees. My sine 0.01 is about 0.6 degree
These conduits (not green) can then be corrected manually.