I am working on a scrip that makes tiles (like for a kitchen floor). I have a script that works perfect on planes for 4 sided tiles. However, I am running into an issues on non-4 sided tiles.
I chose to use cylinders which almost exactly works as needed. But I am hitting an issue on "beveling" (which is just scaling 1 of the faces) the top face of the cylinder.
My code looks at all the faces on the mesh, and
-if it does equal 4 sides, then the script deselects them.
-If it does not equal 4 sides, then runs another check
-If we haven't deleted any faces yet, then it deletes 1 face
-If we have deleted 1 face, then we are on the top face Up to this point works perfectly together
-Then the script scales in the selected face This is where it causes issues
The scaling code works fine on its own if I manually select a face first, and also works fine by hand. I'm not sure if it's a bug or something I'm missing but I could use any help my fellow blender scripters can offer.
I'm including just the face adjusting part of the script, so to test my code you'll have to Add > Mesh > Cylinder to test it out.
Thank you!
(see code and images below)
#Import Python
import bpy
#Import mesh handling
import bmesh
#Import vector
from mathutils import Vector
tileBevelZ = 0.85
#_________________________________________Delete the bottom face
#edit mode
bpy.ops.object.mode_set( mode = 'EDIT' )
#number of faces we've deleted
facesDeleted = 0
#our current object
obj = bpy.context.object
#ref to mesh
bm = bmesh.from_edit_mesh(obj.data)
#for each face in mesh
for f in bm.faces:
#if it's selected
if f.select == True:
#if it does not have the number of sides we want
if len(f.verts) == 4:
#we dont want to select it
f.select = False
# else if it does have the same number of sides
else:
#if we have not deleted a side yet
if facesDeleted == 0:
#deslect 1 of the faces
f.select = False
#increase faces deleted
facesDeleted += 1
#else if we increased our counter
else:
#make sure it's selected
f.select = True
#Delete the face
bpy.ops.mesh.delete(type='FACE')
#set mode to faces
bpy.ops.mesh.select_mode( type = 'FACE' )
#select all
bpy.ops.mesh.select_all(action='SELECT')
#_________________________________________Adjust scale of top face for bevel
#for each face in mesh
for f in bm.faces:
#if it's selected
if f.select == True:
#if it does not have the number of sides we want
if len(f.verts) == 4:
#we dont want to select it
f.select = False
# else if it does have the same number of sides
else:
#make sure it's selected
f.select = True
#set mode to vertices
bpy.ops.mesh.select_mode( type = 'FACE' )
#Scale the face in
bpy.ops.transform.resize(value=(tileBevelZ , tileBevelZ , tileBevelZ), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)