I’m making a script that takes an object, uses a boolean operator to make a slice, and finally separates a single face of that slice. So if I were to take a sphere, it creates a very thin slice of that sphere, and finally separates just a flat circle surface. The first part is all working, but the face separation keeps breaking.
I’m new to both Blender and Python so it’s very difficult to find out what’s going wrong…
The Code:
#######################
# Take a slice and separate a face #
#######################
import bpy
if bpy.context.mode == 'OBJECT': #necessary for correct selection
bpy.context.tool_settings.mesh_select_mode=(False,False,True) #optional
bpy.ops.object.select_all(action='DESELECT')
list(bpy.data.objects)
cube = bpy.data.objects["Cube"]
if cube.type == "MESH":
cube.select = False
m = cube.data
counterFaces = 0
biggestArea = 0
biggestAreaIndex = 0
for face in m.polygons:
if counterFaces == 0:
biggest = face.area
counterFaces += 1
temp = face.area
if temp >= biggest:
biggestAreaIndex = face.index
finalFace = m.polygons[biggestAreaIndex]
print(finalFace.index)
print(finalFace.area)
bpy.context.scene.objects.active = cube
bpy.ops.object.mode_set(mode='EDIT')
finalFace.select = True
bpy.ops.mesh.hide(unselected=True)
bpy.ops.mesh.separate(type='SELECTED')