1
$\begingroup$

With the mesh of the active object, I want to adjust a few edges selected randomly. For that I choose edges, split them in 3 parts and move the related vertices. I'm a beginner in Blender and Python, and would like to use the regular modules, not BMesh. I imagined that:

# Get edges and edge count
edges = mesh.edges
count = len(edges)

# Set EDIT/EDGE mode
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_mode(type='EDGE')

# Pick a few random edges
picked = []
while (count > 0 and len(picked) < 6):
    # Get another random edge
    edge = random.choice(edges)
    if not edge in picked:
        # New edge, use it
        picked.append(edge)
        count -= 1

# Process picked edges
for edge in picked:
    # Select this edge only
    bpy.ops.mesh.select_all(action='DESELECT')
    edge.select = True # Is this correct             <--- ?

    # Split edge in 3 parts
    bpy.ops.mesh.subdivide(number_cuts=2)

    # Get vertices of the 3 parts
    vertices = # how to do that?                     <--- ?

    # Process each vertex
    for vertex in vertices:
        # Do something with the vertex

# Return to object mode
bpy.ops.object.mode_set(mode='OBJECT')

Could you help me filling the 2 marked lines?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.