3
$\begingroup$

I have a simple script which performs Boolean union on multiple meshes. I can manually trace modifier errors in the console and exclude meshes which leads to union artifacts. Here's the script:

import bpy
wm = bpy.context.window_manager
act_obj = bpy.context.active_object
union_list = []
for sel_obj in bpy.context.selected_objects:
    if sel_obj.type == 'MESH':
        if sel_obj != act_obj:
            bpy.ops.object.modifier_add(type="BOOLEAN")
            union_list.append(sel_obj)

k=0
union_list_len = len(union_list)
wm.progress_begin(0, union_list_len)

for mod in act_obj.modifiers:
    if mod.type == "BOOLEAN":
        print(k,union_list_len,union_list[k].name)
        wm.progress_update(k)
        mod.operation = "UNION"
        mod.object = union_list[k]
        bpy.ops.object.modifier_apply(modifier=mod.name)
        k=k+1
act_obj.select = False
bpy.ops.object.delete()
wm.progress_end()

Is there a way to catch Boolean modifier error in python and skip meshes which produce those errors?

$\endgroup$
4
  • $\begingroup$ Here's a related Addon which may be useful as reference. wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Object/… $\endgroup$ Commented May 5, 2015 at 2:40
  • $\begingroup$ Hey @Bartłomiej Szczepaniak . Is this really still an open question? $\endgroup$
    – Teck-freak
    Commented Nov 28, 2017 at 9:00
  • $\begingroup$ @Teck-freak nope, just forgot about ☑ $\endgroup$ Commented Dec 3, 2017 at 11:10
  • $\begingroup$ @BartłomiejSzczepaniak Great. Thanks and happy blending. $\endgroup$
    – Teck-freak
    Commented Dec 6, 2017 at 22:58

1 Answer 1

1
$\begingroup$

Well the easy way would be to use a try-except catch

This would skip the meshes where errors happen print their names and reselect them after deleting the rest:

import bpy
wm = bpy.context.window_manager
act_obj = bpy.context.active_object
union_list = []
passed = []
for sel_obj in bpy.context.selected_objects:
    if sel_obj.type == 'MESH':
        if sel_obj != act_obj:
            try:
                bpy.ops.object.modifier_add(type="BOOLEAN")
                union_list.append(sel_obj)
            except:
                print("\n"+sel_obj.name)
                passed.append(sel_obj)
                sel_obj.select = False

k=0
union_list_len = len(union_list)
wm.progress_begin(0, union_list_len)

for mod in act_obj.modifiers:
    if mod.type == "BOOLEAN":
        print(k,union_list_len,union_list[k].name)
        wm.progress_update(k)
        mod.operation = "UNION"
        mod.object = union_list[k]
        try:
            bpy.ops.object.modifier_apply(modifier=mod.name)
        except:
            print("\n"+sel_obj.name)
            passed.append(sel_obj)
            sel_obj.select = False
        k=k+1
act_obj.select = False
bpy.ops.object.delete()
wm.progress_end()
for obj in passed: obj.select = True

hope it helps, Teck-Freak

$\endgroup$
2
  • $\begingroup$ you have added the try in the wrong place it should be around modifier_apply() $\endgroup$
    – Chebhou
    Commented May 28, 2015 at 18:36
  • $\begingroup$ thx Chebhou. I'll fix it $\endgroup$
    – Teck-freak
    Commented May 28, 2015 at 18:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .