Snippets
Various little code snippets helping with Blender scripting!
Collecting face islands (aka shells) as a list of lists of faces
You can do it easier, as there is a function for this already:
bpy.ops.mesh.select_linked(delimit={'SEAM'})
Implemented as a simplified a*-algorithm.
def get_face_islands(obj):
""" Returns a list of island lists """
id=0
islands=[]
open_faces=list(obj.data.polygons)
while open_faces:
face=open_faces.pop()
test_faces=[]
test_faces.append(face)
islands.append([])
islands[id].append(face)
while test_faces:
face=test_faces.pop()
for vert in face.vertices:
new_open=[]
while open_faces:
new_face=open_faces.pop()
if vert in new_face.vertices:
test_faces.append(new_face)
islands[id].append(new_face)
else:
new_open.append(new_face)
open_faces=new_open
id+=1
return islands
Progress Bar
The easiest is the internal window manager:
import bpy
wm = bpy.context.window_manager
# progress from [0 - 1000]
tot = 1000
wm.progress_begin(0, tot)
for i in range(tot):
wm.progress_update(i)
wm.progress_end()
There is a complex one on stackexchange