Skip to content

Instantly share code, notes, and snippets.

@zeffii zeffii/proof.py
Last active Aug 29, 2015

Embed
What would you like to do?
import bpy
import bmesh
import time
US = lambda: bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
# START WITH CUBE or low vertex number mesh selected.
ao = bpy.context.active_object
oo = bpy.ops.object
oo.mode_set(mode='EDIT')
me = bmesh.from_edit_mesh(ao.data)
nverts = len(me.verts)
print(nverts)
for i in range(2):
for iv in range(nverts):
me.verts.ensure_lookup_table()
me.verts[iv].select = True # light them up one at a time
US() #update screen
time.sleep(0.5)
for iv in range(nverts):
me.verts.ensure_lookup_table()
me.verts[iv].select = False # turn them off one at a time
US() #update screen
time.sleep(0.5)
import bpy
import bmesh
import time
US = lambda: bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
# START WITH CUBE or low vertex number mesh selected.
ao = bpy.context.active_object
oo = bpy.ops.object
oo.mode_set(mode='EDIT')
me = bmesh.from_edit_mesh(ao.data)
nverts = len(me.verts)
print(nverts)
for i in range(2):
for b in [1, 0]:
for v in me.verts:
v.select = b
US() #update screen
time.sleep(0.5)
@zeffii

This comment has been minimized.

Copy link
Owner Author

zeffii commented Aug 1, 2015

The lambda is in essence a single line function declaration, a shorthand for functions which really don't have much going on, but at the same you just clutter the code if you always pass the same arguments. In this case the lambda allows the execution of a function with pre-filled arguments.

The following are functional equivalents in this scenario.

def US():
    bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)

and

US = lambda: bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)

One could pass arguments to the lambda.. but then you might as well be using a function definition with default arguments if there's a set of arguments that would get passed most frequent

US = lambda t, i : bpy.ops.wm.redraw_timer(type=t, iterations=i)
US('DRAW_WIN_SWAP', 1)

#vs
def US(draw_type='DRAW_WIN_SWAP', iterations=1):
    bpy.ops.wm.redraw_timer(type=draw_type, iterations=iterations)

US()
US('DRAW_WIN_SWAP', 1)
US(iterations=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.