Viewport alignment on grids instead ViewportBoxCentre

I’m currently making a script for the alignment of views from a main view.
I would like to create a combination of 2 methods:

  1. The alignment of views on middle using the viewport outline (BoundingboxXYZ).
  2. The alignment of viewports on the model grids. (like the guide grid method)

The first part was not hard at all but the second part has been on my mind for the past week…

The workflow I had in mind but doesn’t seem doable with the current API is the following:

  • getting the delta value of your grid line X or Y and the viewport middle of 2 viewports and then correcting the viewport middle to the difference in the delta value.

But I have no idea how to retrieve the position of elements in views on a sheet.

Please share your thoughts on the workflow and I would like to hear experiences from others.

Kind regards,

Timo