As in title, I'm trying to extrude mesh via python as I have ~1.5k objects to extrude and when I do it in editor it works perfectly but when I run it via python it always go wrong. It just move face and I'm missing one face. So I tried to create it but I can create only half of it for some reason. Can somebody help?
Code:
import bpy, bmesh
for obj in bpy.context.scene.objects:
if obj.name.startswith("Exterior"): # Name
print(obj.name)
bpy.context.scene.objects.active = obj
# Go to edit mode, face selection mode and select all faces
bpy.ops.object.mode_set( mode = 'EDIT' ) # Toggle edit mode
bpy.ops.mesh.select_mode( type = 'FACE' ) # Change to face selection
bpy.ops.mesh.select_all( action = 'SELECT' ) # Select all faces
# As extrude move forward base face it needs to be saved
bm = bmesh.new() # create an empty BMesh
bm = bmesh.from_edit_mesh(bpy.context.object.data)
meshVertices = [e for e in bm.verts]
# Flip normals
#bpy.ops.mesh.flip_normals()
# Extrude
bpy.ops.mesh.extrude_faces_move(
MESH_OT_extrude_faces_indiv={"mirror": True},
TRANSFORM_OT_shrink_fatten={"value": -0.4, # Dirrection and size of extrude
"mirror": False,
"proportional": 'DISABLED',
"proportional_edit_falloff": 'SMOOTH',
"proportional_size": 1,
"snap": False,
"snap_target": 'CLOSEST',
"snap_point": (0, 0, 0),
"snap_align": False,
"snap_normal": (0, 0, 0),
"release_confirm": False})
# Add face
bm.faces.new(meshVertices) # len(meshVertices)
# Update & Destroy BMESH
bmesh.update_edit_mesh(bpy.context.object.data) # Write the bmesh back to the mesh
bm.free() # free and prevent further access
# At end recalculate UV
bpy.ops.mesh.select_all( action = 'SELECT' )
bpy.ops.uv.smart_project()
# Switch back to Object at end
bpy.ops.object.mode_set( mode = 'OBJECT' )
# Origin
#bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
Mesh to be extruded.
Extruded mesh.
Second side of extruded mesh.
PS: Mesh is just a 4 vertices square (one face) and I'm trying to make it 3d from 2d