Getting size of vtkTextActor in python

Hello everyone, I would like to know the width and height of a vtkTextActor in python. According to the documentation, the GetSize and GetBoundingBox should provide me the height and width and those said methods require vtkViewport as one of its parameters. But I wanted to gain this information without passing a vtkViewport instance. Also, I tried the GetPosition2 method but its value is always set to (0.5, 0.5, 0) irrespective of the font size of vtkTextActor. It would be great if someone could provide me way to gain this information.

Thank You.

It’s not possible to determine the pixel size of the rendered text without the viewport, since the size of the rendered text is dependent on the DPI of the target display.

A vtkRenderer is a type of vtkViewport, so you should pass in the renderer that draws the actor.

The Position2 coordinate is not used unless the TEXT_SCALE_MODE_PROP mode is being used on the text actor. See vtkTextActor::SetTextScaleModeToProp().

Hello @AllisonVacanti, thank you for your response. Could you suggest me a workaround or a manual method by which I could achieve this?

You’ll need to find the instance of vtkRenderer that contains the text actor and pass that renderer in as the viewport argument of GetSize(...).

1 Like