How to draw a line on sagittal view

For the application I am working on, I would like to draw horizontal lines in the sagittal view to mark specific slices that I am interested in. Is there code that can help me achieve this?

I know that in the Markups module I can use a button to draw a markup line, I would like something similar to that.

Thanks in advance!

Markup lines or planes should work well for this. You can place them easily from Python script: add a markups line/plane node to the scene and set control point positions.

For the python script do you mean:

There are several relevant examples, see here:

thank you very much!