Uncategorized

subdivide_edges VS Loop cut in Python


Please explain why my attached code does not exshibit a cut line in the 3d Viewport on the top face of the cube. Also I’d appreciatre an explanation of the differeces between loopcut and subdivide_edges.

import bpy

import bmesh

def create_cube_foundation(cube_size=20, location=(0, 0, 0), rotation=(0, 0, 0), scale=(1, 1, 1)):
    # Create a cube
    bpy.ops.mesh.primitive_cube_add(size=cube_size, location=location)
    cube = bpy.context.object

# Set cube rotation and scale
cube.rotation_euler = rotation
cube.scale = scale

# Ensure we're in object mode with the correct object active
bpy.ops.object.mode_set(mode="OBJECT")
bpy.context.view_layer.objects.active = cube
bpy.ops.object.mode_set(mode="EDIT")

# Create a bmesh from the cube mesh
mesh = bmesh.from_edit_mesh(cube.data)

# Add a loop cut using bmesh operations
ret = bmesh.ops.subdivide_edges(mesh, edges=mesh.edges, cuts=1, use_grid_fill=True)

# Update the mesh with the new data
bmesh.update_edit_mesh(cube.data)
bpy.ops.object.mode_set(mode="OBJECT")

# Rest of your code...

create_cube_foundation()



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *