script boolean sum object mesh error


(Titanium921) #1

Hello,this is my script,I want to boolean sum 2 object(Cube and Cube.001),when i select Cube.001 and run this script, there is an error,and the modifier added on Cube.001, When I selected Cube and run script,sometimes the script will sucessed,sometimes error.
I do not known why?


import bpy
class Merge:
‘’‘Merge mesh together’’’
def join(obj1,obj2):
bpy.ops.object.select_all(action=“DESELECT”)
obj1.select=True
bpy.ops.object.modifier_add(type=‘BOOLEAN’)
obj1.modifiers[“Boolean”].operation = ‘UNION’
obj1.modifiers[“Boolean”].object = obj2
bpy.ops.object.modifier_apply(apply_as=‘DATA’, modifier=“Boolean”)
bpy.ops.object.select_all(action=“DESELECT”)
obj2.select=True
bpy.ops.object.delete(use_global=False)

Merge.join(bpy.data.objects[“Cube”],bpy.data.objects[“Cube.001”])