Force screen updating

Not all actions made with the Blender Python API cause Blender to immediately redraw the screen. Therefore, quite often it is necessary to force a screen refresh so that the user immediately sees all the changes.

For example, let’s draw a circle on the 3D viewport area using the “gpu” module.

If we execute this code from the Blender Text Editor by pressing the “execute script” button with arrow, at first we will not see any changes on the viewport. To see the drawn circle, we need to move the cursor to the 3D viewport area and perform some action, for example, change the scale by turning the mouse wheel. At this moment, the viewport is updated, and we see all the changes at once.

To save the user the trouble of manually refreshing the screen, we can force a screen redraw by executing the following code:

After its execution, all open areas, including the viewport, will be updated.

To redraw only the 3D viewport area, we can limit the call by area type:

This code will cause only the 3D viewport area to be redrawn.

Screen redrawing can also be done with the redraw_timer() operator.

Although this operator is provided by the developers to measure screen redraw speed, it redraws the entire screen as it runs, which is what we need.

5 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments