Skip to content

Commit 535458a

Browse files
author
rking
committed
Woohoo! Iterate over all selected objects.
This is a small change, but I am very excited about it. Now you can hit 'a' to select all meshes in the Scene, and click "Select Lint". It will start with the active object then go through all selected, stopping at the first one with a problem.
1 parent 524e682 commit 535458a

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

meshlint.py

+39-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# TODO:
22
# - Exempt mirror-plane verts.
3+
# - Check for intersected faces??
4+
# - Would probably be O(n^m) or something.
5+
# - Would need to check the post-modified mesh (e.g., Armature-deformed)
36

47
bl_info = {
58
"name": "MeshLint: Like Spell-checking for your Meshes",
@@ -33,9 +36,11 @@ def __init__(self):
3336
self.obj = bpy.context.active_object
3437
self.ensure_edit_mode()
3538
self.b = bmesh.from_edit_mesh(self.obj.data)
39+
self.num_problems_found = None
3640

3741
def find_problems(self):
3842
analysis = []
43+
self.num_problems_found = 0
3944
for lint in MeshLintAnalyzer.CHECKS:
4045
sym = lint['symbol']
4146
should_check = getattr(bpy.context.scene, lint['check_prop'])
@@ -51,9 +56,13 @@ def find_problems(self):
5156
indices = bad.get(elemtype, [])
5257
report[elemtype] = indices
5358
lint['count'] += len(indices)
59+
self.num_problems_found += len(indices)
5460
analysis.append(report)
5561
return analysis
5662

63+
def found_zero_problems(self):
64+
return 0 == self.num_problems_found
65+
5766
@classmethod
5867
def none_analysis(cls):
5968
analysis = []
@@ -64,9 +73,15 @@ def none_analysis(cls):
6473
return analysis
6574

6675
def ensure_edit_mode(self):
76+
self.previous_mode = bpy.context.mode
6777
if 'EDIT_MESH' != bpy.context.mode:
6878
bpy.ops.object.editmode_toggle()
6979

80+
def restore_previous_mode(self):
81+
if 'EDIT_MESH' != self.previous_mode:
82+
bpy.ops.object.editmode_toggle()
83+
self.previous_mode = None
84+
7085
CHECKS.append({
7186
'symbol': 'tris',
7287
'label': 'Tris',
@@ -287,6 +302,11 @@ def execute(self, context):
287302
MeshLintVitalizer.is_live = True
288303
return {'FINISHED'}
289304

305+
306+
def activate(obj):
307+
bpy.context.scene.objects.active = obj
308+
309+
290310
class MeshLintSelector(bpy.types.Operator):
291311
'Uncheck boxes below to prevent those checks from running'
292312
bl_idname = 'meshlint.select'
@@ -298,6 +318,17 @@ def poll(cls, context):
298318
return has_active_mesh(context)
299319

300320
def execute(self, context):
321+
original_active = bpy.context.active_object
322+
for obj in bpy.context.selected_objects:
323+
activate(obj)
324+
good = self.active_object_passes()
325+
if not good:
326+
context.area.tag_redraw()
327+
return {'FINISHED'}
328+
activate(original_active)
329+
return {'FINISHED'}
330+
331+
def active_object_passes(self):
301332
analyzer = MeshLintAnalyzer()
302333
analyzer.enable_anything_select_mode()
303334
self.select_none()
@@ -306,11 +337,15 @@ def execute(self, context):
306337
for elemtype in ELEM_TYPES:
307338
indices = lint[elemtype]
308339
analyzer.select_indices(elemtype, indices)
309-
context.area.tag_redraw()
340+
# TODO: Double-check this. I have the feeling it's already taken care
341+
# of inside find_problems() --
310342
# Record this so the first time the user hits "Continuous Check!" it
311343
# doesn't spew out info they already knew:
312344
MeshLintContinuousChecker.previous_analysis = analysis
313-
return {'FINISHED'}
345+
clean = analyzer.found_zero_problems()
346+
if clean:
347+
analyzer.restore_previous_mode()
348+
return clean
314349

315350
def select_none(self):
316351
bpy.ops.mesh.select_all(action='DESELECT')
@@ -329,8 +364,7 @@ def poll(cls, context):
329364
def draw(self, context):
330365
layout = self.layout
331366
self.add_main_buttons(layout)
332-
if 'EDIT_MESH' == bpy.context.mode:
333-
self.add_rows(layout, context)
367+
self.add_rows(layout, context)
334368

335369
def add_main_buttons(self, layout):
336370
split = layout.split()
@@ -366,6 +400,7 @@ def add_rows(self, layout, context):
366400
reward = 'ERROR'
367401
row = col.row()
368402
row.prop(context.scene, lint['check_prop'], text=label, icon=reward)
403+
# TODO: Make this iterate over selected.
369404
if MeshLintControl.has_bad_name(active.name):
370405
col.row().label(
371406
'...and "%s" is not a great name, BTW.' % active.name)

0 commit comments

Comments
 (0)