problems with 'Blender.Redraw()'...


When drawing a mesh with python (see the script appended) and manipulating its location, blender doesn’t update its views. I first thought, the ‘setLocation()’ function doesn’t work as I expected, but when I select the plane and push ‘s’ (scale) or ‘g’ (grab), the view finally gets updated and the translation shown.

I would like to manipulate objects interactively using scripts, so here my question: Is there some other, more immediate way than ‘Blender.Redraw()’ to update the view from python?

Thanks, Dietrich


an example script:


import os
import Blender
from Blender import NMesh

mesh object:

plane = NMesh.GetRaw()

vertice at the center of discus:

plane.verts.append( NMesh.Vert( -1.0, -1.0, 0.0 ) )
plane.verts.append( NMesh.Vert( 1.0, -1.0, 0.0 ) )
plane.verts.append( NMesh.Vert( 1.0, 1.0, 0.0 ) )
plane.verts.append( NMesh.Vert( -1.0, 1.0, 0.0 ) )

making the face:

f = NMesh.Face()
f.v.append( plane.verts[ 0 ] )
f.v.append( plane.verts[ 1 ] )
f.v.append( plane.verts[ 2 ] )
f.v.append( plane.verts[ 3 ] )
plane.faces.append( f )

making the mesh a new object:

planeObj = NMesh.PutRaw( plane, ‘Plane’, 1 ) # 1: recomputation of normals on each node

update scene:


print “sleeping…”;
os.system( “sleep 1” )
print “waking up…”;

translate the plane and redraw:

planeObj.setLocation( 1.0, 2.0, 3.0 )

no, there isn’t
[Blender.Draw.Redraw() will redraw blender, but doesn’t work every time… it is often queued [as documented]]

I’m not the nmesh expert but i think you need an mesh.update() in there somewhere (not sure :))

Hi ,

Thanks for your answer! - and sorry for answering so late…

Trying the following commands:

  • Blender.Redraw()
  • Blender.Draw.Redraw()
  • Blender.Draw.Redraw( 1 )
  • Blender.Draw.Draw()

with and without

  • plane.update()

I could observe the following results:

  • the behavior with or without ‘plane.update()’ was in all cases the same.
  • the first draw command (the one I originally used) shows the mesh immediately but doesn’t display its translation. (Even when I used one of the other three draw commands in combination with the first one, the translation would not be shown.)
  • the other three draw commands all caused the following behavior:
    the mesh would be shown only after the “sleep” but with the translation applied to it. Probably the draw command is called only once after the script’s execution is completed.

What I wanted is some command showing the position of the mesh before and after the translation. This was the behavior of the script in one of the older blender versions (2,36?) but it seems not to be realizable anymore.

At least the last three draw commands show the mesh in its final position and it seems I have to be happy with them.

Greetings, Dietrich

try Blender.Scene.GetCurrent().update(1)