how to extrude a region of self-selected vertices in python?

hello
My ultimate goal is to modify the sphere so i get something as you can see on the figure below (but in 3D, instead of 2D):


–> i created an ico-sphere and selected a set of vertices on that sphere (i.e., for z coordinateds > 0.95 and x,y coordinates belonging to a circle with radius = 0.1). I managed to select these vertices w/ indeces, x-, y-, & z-coordinates
–> In a next step, I want to extrude these selected vertices as a region. I do not succeed though (notthing happens :()…any suggestions please? Or, should i use another modifier?

thx!

#----------------------------------------------------------
print(’########################################’)
print(’########## Extrude in Python #################’)
print(’########################################’)
#----------------------------------------------------------

import bpy
import math
import os
import sys
import bmesh
from math import cos, sin, tan, pi, sqrt, atan
from mathutils import *

Delete all potential objects in the scene

bpy.ops.object.select_all(action=‘SELECT’)
bpy.ops.object.delete()

Make a shortcut to the current scene:

sce = bpy.context.scene

Create an icosphere

origin = (0,0,0)
bpy.ops.mesh.primitive_ico_sphere_add(location=origin, subdivisions = 3) # create an “ico-sphere”
shell_in_ob = bpy.context.object
shell_in_me = shell_in_ob.data

shell_in_ob.scale[0]= 1.0 # scale the half axis in x direction to preset dimension
shell_in_ob.scale[1]= 1.0 # scale the half axis in y direction to preset dimension
shell_in_ob.scale[2]= 1.0 # scale the half axis in z direction to preset dimension

collect selected vertices we want to extrude as a region

bpy.ops.object.mode_set(mode = ‘EDIT’)

selected_idx = [i.index for i in shell_in_me.vertices if i.select]
print(‘selected_idx’, selected_idx)

count = 0
x_selected = []
y_selected = []
z_selected = []
index_selected = []

for v_index in selected_idx:
vert_coordinate_x = shell_in_me.vertices[v_index].co.x
vert_coordinate_y = shell_in_me.vertices[v_index].co.y
vert_coordinate_z = shell_in_me.vertices[v_index].co.z
if vert_coordinate_z > 0.95 and (pow(vert_coordinate_x,2.0) + pow(vert_coordinate_y,2.0) <= 0.1):
print(‘yes, i pass, index =’, v_index, ’ ')
count += 1
x_selected.extend([vert_coordinate_x])
y_selected.extend([vert_coordinate_y])
z_selected.extend([vert_coordinate_z])
index_selected.extend([v_index])

print(‘x_selected =’,x_selected)
print(‘y_selected =’,y_selected)
print(‘z_selected =’,z_selected)
print(‘index_selected=’,index_selected)

Select selected vertices we want to extrude as a region

bpy.ops.mesh.select_all(action=‘DESELECT’)
for v_index in index_selected:
bpy.data.meshes[‘Icosphere.012’].vertices[v_index].select = True
print('v_index = ', v_index)
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={“mirror”:False}, TRANSFORM_OT_translate={“value”:(2, 2, 2), “constraint_axis”:(False, False, False), “constraint_orientation”:‘GLOBAL’, “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), “texture_space”:False, “release_confirm”:False})

bpy.ops.object.mode_set(mode=‘OBJECT’)

Attachments