Hello,
I am trying to do a slicing script based on mesh bisect that will cut me any object, say in the z direction in x slices of a certain thickness and preserve the original object.
Right now, I am just trying the basics in a simple script but can not get two bisect operations to work after each other.
This script works with the default cube selected from the default scene and should have resulted right now in slicing a 0.1 unit piece from z=0 to z=0.1
the first bisect works, the second does not
Why can I not do two bisect after each other ? Tried to use bpy.ops.mesh.select_all() to select all vertices but that does not help.
Help appreciated.
import bpy
def duplicateObject(scene, name, copyobj):
# Create new mesh
mesh = bpy.data.meshes.new(name)
# Create new object associated with the mesh
ob_new = bpy.data.objects.new(name, mesh)
# Copy data block from the old object into the new object
ob_new.data = copyobj.data.copy()
ob_new.scale = copyobj.scale
ob_new.location = copyobj.location
# Link new object to the given scene and select it
scene.objects.link(ob_new)
ob_new.select = True
return ob_new
print()
print ("Script start")
thickness=0.1
slices=3
scene = bpy.context.scene
# Note sur bound_box for v in bpy.data.objects["Cube"].bound_box
activeObjects=bpy.context.selected_objects
for activeObject in activeObjects:
for slicenr in range(0,1):
slicename="slice"+str(slicenr)
print("Now doing slice "+slicename)
cobj=duplicateObject(scene,slicename,activeObject)
#bpy.ops.object.select_all(action='DESELECT')
#bpy.ops.object.select_pattern(pattern="slice0")
bpy.context.scene.objects.active = bpy.data.objects[slicename]
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.bisect(plane_co=(0,0,0),plane_no=(0,0,1),xstart=0,xend=100,ystart=0,yend=100,clear_outer=False,clear_inner=True)
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all()
print(thickness*(1+slicenr))
bpy.ops.mesh.bisect(plane_co=(0,0,0+thickness*(1+slicenr)),plane_no=(0,0,1),xstart=0,xend=100,ystart=0,yend=100,clear_outer=True,clear_inner=False)