How to put a text in the center of a renderview?

Dear All,

I am trying to put a text in the center of the renderview on the specific height Oy, not center bottom. How to do it?
I am using pvpython. setting position is not suitable, because I don’t know the length

BR,
Evgenii

  • Source -> Text, Apply
  • check “Lower left corner” and position the text

Dear Mathieu,

Yes indeed, I will able to specify position, but the position corresponds to the lower-left corner. I need to specify the position according to the center of the text.
I want to automate the generation of pictures with some data on them.

BR,
Evgenii

You will need to recover the 2D bounds of your text actor, may be doable in Python.

I tryed this to get bounds info: but it does not work:

        text1 = Text()
        text1.Text = 'x=' + str(round(sl,2)) + " l/l_b=" + str(round((sl-bounds[0])/len_bub,2))

        text1Display = Show(text1, renderView2, 'TextSourceRepresentation')

        # trace defaults for the display properties.
        text1Display.WindowLocation = 'AnyLocation'
        text1Display.Position = [0.3, 0.2]
        textBounds = text1.GetDataInformation().GetBounds()
        print("textBounds=",textBounds)

It shows
('textBounds=', (1e+299, -1e+299, 1e+299, -1e+299, 1e+299, -1e+299))

BR,
Evgenii

Text()
rep=Show()
Render()
rep.Position2

Dear Mathieu,

I have tried this but it shows the same number for any text.

then I tried another to find out the width of a text:

text1=Text()
text1.Text="my text"
text1Display = Show(text1)
text1Display.WindowLocation = 'UpperCenter';
Render()
print text1Display.Position2, text1Display.Position

the output is

<paraview.servermanager.RenderView object at 0x12689b650>

[0.1, 0.1] [0.05, 0.05]

The outout is not correct.

BR,
Evgenii

It looks like this is not updated properly, this is a bug.

Replicated. Reported here: https://gitlab.kitware.com/paraview/paraview/-/issues/20226