I am trying to merge two close boxes into one single cuboid, from the GUI I am able to successfully create the two boxes and set a boolean modifier to the first box to unify(UNION) with the second box before deleting it. But when I run the following script
import bpy
import ast
def delete(obj0):
bpy.ops.object.select_all(action='DESELECT')
obj0.select = True
bpy.ops.object.delete()
def Merge(obj0,obj1):
bpy.ops.object.select_all(action='DESELECT')
obj0.select = True #selecting obj0 so the bpy modifier is constructed for it
bpy.ops.object.modifier_add(type='BOOLEAN')
bpy.context.object.modifiers["Boolean"].object = obj1
bpy.context.object.modifiers["Boolean"].operation = 'UNION'
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Boolean")
delete(obj1) #deleting obj1 since it's no longer needed
return obj0 #returning obj0 which shoulda become the cuboid just incase a future need arises to merge with another box
def AddBox(x,y,z,width,height,depth):
bpy.ops.mesh.primitive_cube_add(location=(x, y, z))
bpy.ops.transform.resize(value=(width, height, depth))
return bpy.context.active_object
#creating the two boxes and naming them
box0 = AddBox(0,0,0, .5,.5,.5)
box0.name='box0'
box1 = AddBox(0,1,0, .5,.5,.5)
box1.name='box1'
#merging them into a cuboid
Merge(box0,box1)
I get the following exception
TypeError: bpy_struct: item.attr = val: BooleanModifier.object ID type does not support assignment to itself