Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/bmesh_simple_editmode.py
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/6f4634a9d3b6a56ef6e4 to your computer and use it in GitHub Desktop.
Save zeffii/6f4634a9d3b6a56ef6e4 to your computer and use it in GitHub Desktop.
import bpy
import bmesh
import random
def deselect(bm):
for f in bm.faces:
f.select = False
def pick_two_random_faces(bm):
for i in random.sample(range(len(bm.faces)), 2):
bm.faces[i].select = True
# Get the active mesh
obj = bpy.context.edit_object
me = obj.data
# Get a BMesh representation
bm = bmesh.from_edit_mesh(me)
bm.faces.ensure_lookup_table()
bm.faces.active = None
deselect(bm)
for i in range(10):
pick_two_random_faces(bm)
bpy.ops.mesh.add_curvebased_tube(main_scale=0.3)
deselect(bm)
# Show the updates in the viewport
# and recalculate n-gon tessellation.
bmesh.update_edit_mesh(me, True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment