[Bf-python] bpy candy - new features

Willian Padovani Germano wgermano at ig.com.br
Thu Jul 22 23:54:02 CEST 2004


Hi,

First of all, cool additions, Stephen : ), curve / surface stuff is getting
very good.

During the work for the demo mode I've added event queue related methods to
Blender.Window.  With them some nifty things should be possible now, though
there's still work to do.

I guess the event loops now possible can serve as what Manuel once asked for
the BlenderCad project.  Maybe also already for scripts like Löic's
bevel_center.py.  Face extruding using normal directions (Jean-Michel had
one, right?) is another example of scripts that can benefit.

Anyway, if you have a recent Blender compiled from cvs (check that it has
Blender.Window.QRead, for example), the script below should work.  It's just
a test, but once well tuned, many scripts can benefit from this "closer to
Blender's way of interaction" method.

I've tweaked the code a little to get some needed speed-ups, but there may
still be room for improvement, by making a subloop once a MOUSEX event is
caught, using Window.GetMouseCoords() and Window.GetMouseButtons().  There's
another example in the Window.py doc file under api2_2x/doc/ while there's
no updated ref doc around.

Note: after selecting verts you may need to leave (and if wanted re-enter)
editmode once before running the script.   We need to add undo_push_mesh(),
etc. to bpython to handle this properly, it seems.

# Simplistic example of event queue control from bpython
# Have a mesh called "Cube", select some of its verts (a face perpendicular
# to the x axis would be ideal), then execute the script.
# Move the mouse gently and press left mouse button when done.
# Requirement: a recent Blender from cvs.  2.34 will also do, when released.
# Suddenly I feel the need for a Blender.EMesh module, to speed things up
:),
# it should be available for 2.35.

import Blender
from Blender import NMesh
from Blender.Draw import *
from Blender.Window import *

m = NMesh.GetRaw("Cube")

is_editmode = EditMode()

if is_editmode:
  EditMode(0)
  Redraw() # redraw 3dview

evt = 0
mx = my = 0

# Ok, this is slow with nmesh.update, so let's help by putting
# selected verts in a list so we don't need to check all verts in the loop:
vs = []
for v in m.verts:
 if v.sel:
  vs.append(v)

# the loop: stop when ESC or LEFTMOUSE button are pressed
while evt != ESCKEY:
  evt, val = QRead()
  incr = 0
  if evt == MOUSEX:
    if val > mx + 3: incr = 0.1
    elif val < mx - 3: incr = -0.1
    if incr:
     mx = val
     for v in vs:
       v.co[0] += incr
     m.update() # the bottleneck, that Blender.EMesh will solve
     Redraw() # 3D View
  #elif evt == MOUSEY:
  # ...
  elif evt == LEFTMOUSE:
    evt = ESCKEY

# not that slow after doing a few optimizations, but this example is too
# simple anyway.

if is_editmode: EditMode(1)

--
Willian, wgermano at ig.com.br




More information about the Bf-python mailing list