1
$\begingroup$

I'm creating a conical frustum in blender using a function. The problem occurs when I extrude the upper ring of the mesh after adding a few loop cuts. For some reason the script doesn't just extrude the upper ring, but all created loop cuts. It seems that there isn't a command in the context, that specifies that I have only selected the upper ring before the extrusion and so it extrudes all the loop cuts, since they stay active after I add them.

Can someone explain to me how to ensure that it only extrudes the last selected part of the mesh?

import bpy

# Reset scene/delete all objects
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)

def create_NS(r1,r2):
    
    '''Create a Normschliff from inputs for dimensions
    of a frustum. r1 < r2. Supply r1, r2 in mm (int).
    h is set as a constant factor based on the values 
    of r1,r2.'''
    
    def get_override():
        
        '''Obtains the current overwrite for a scene...or something.'''
    
        for area in bpy.context.screen.areas:
            if area.type == 'VIEW_3D':
                for region in area.regions:
                    if region.type == 'WINDOW':
                        override = {'area': area, 'region': region, 'edit_object':bpy.context.edit_object}
        
        return override

    
    h = h_dict = {'29/32':55}[str(r1)+'/'+str(r2)]
    
    bpy.ops.mesh.primitive_circle_add(vertices=64, 
                                      radius=r1/100, 
                                      enter_editmode=False, 
                                      align='WORLD', 
                                      location=(0, 0, 0), 
                                      scale=(1, 1, 1))
                                      
    bpy.ops.object.shade_smooth()
    bpy.ops.object.editmode_toggle()
                 
    bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"use_normal_flip":False,
                                                             "use_dissolve_ortho_edges":False, 
                                                             "mirror":False}, 
                                     TRANSFORM_OT_translate={"value":(0, 0, h/100), 
                                                             "orient_axis_ortho":'X', 
                                                             "orient_type":'GLOBAL', 
                                                             "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), 
                                                             "orient_matrix_type":'GLOBAL', 
                                                             "constraint_axis":(True, True, True), 
                                                             "mirror":False, 
                                                             "use_proportional_edit":False, 
                                                             "proportional_edit_falloff":'SMOOTH', 
                                                             "proportional_size":1, 
                                                             "use_proportional_connected":False, 
                                                             "use_proportional_projected":False, 
                                                             "snap":False, 
                                                             "snap_target":'CLOSEST', 
                                                             "snap_point":(0, 0, 0), 
                                                             "snap_align":False, 
                                                             "snap_normal":(0, 0, 0), 
                                                             "gpencil_strokes":False, 
                                                             "cursor_transform":False, 
                                                             "texture_space":False, 
                                                             "remove_on_cancel":False, 
                                                             "view2d_edge_pan":False, 
                                                             "release_confirm":False, 
                                                             "use_accurate":False, 
                                                             "use_automerge_and_split":False})
    scaling_fac = r2/r1
    
    bpy.ops.transform.resize(value=(scaling_fac, scaling_fac, scaling_fac), 
                             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)
    
    
    override = get_override()
    bpy.ops.mesh.loopcut_slide(override,
                               MESH_OT_loopcut={"number_cuts":4, 
                                                "smoothness":0, 
                                                "falloff":'INVERSE_SQUARE', 
                                                "object_index":0, 
                                                "edge_index":131, 
                                                "mesh_select_mode_init":(True, False, False)}, 
                                TRANSFORM_OT_edge_slide={"value":0, 
                                                         "single_side":False, 
                                                         "use_even":False, 
                                                         "flipped":False, 
                                                         "use_clamp":True, 
                                                         "mirror":False, 
                                                         "snap":False, 
                                                         "snap_target":'CLOSEST', 
                                                         "snap_point":(0, 0, 0), 
                                                         "snap_align":False, 
                                                         "snap_normal":(0, 0, 0), 
                                                         "correct_uv":True, 
                                                         "release_confirm":False, 
                                                         "use_accurate":False})
    
    
    bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"use_normal_flip":False, 
                                                             "use_dissolve_ortho_edges":False, 
                                                             "mirror":False}, 
                                                             TRANSFORM_OT_translate={"value":(0, 0, 0.15), 
                                                                                     "orient_axis_ortho":'X', 
                                                                                     "orient_type":'GLOBAL', 
                                                                                     "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), 
                                                                                     "orient_matrix_type":'GLOBAL', 
                                                                                     "constraint_axis":(False, False, True), 
                                                                                     "mirror":False, 
                                                                                     "use_proportional_edit":False, 
                                                                                     "proportional_edit_falloff":'SMOOTH', 
                                                                                     "proportional_size":1, 
                                                                                     "use_proportional_connected":False, 
                                                                                     "use_proportional_projected":False, 
                                                                                     "snap":False, "snap_target":'CLOSEST', 
                                                                                     "snap_point":(0, 0, 0), 
                                                                                     "snap_align":False, 
                                                                                     "snap_normal":(0, 0, 0), 
                                                                                     "gpencil_strokes":False, 
                                                                                     "cursor_transform":False, 
                                                                                     "texture_space":False, 
                                                                                     "remove_on_cancel":False, 
                                                                                     "view2d_edge_pan":False, 
                                                                                     "release_confirm":False, 
                                                                                     "use_accurate":False, 
                                                                                     "use_automerge_and_split":False})
    



create_NS(29,32)                     

comparison

$\endgroup$
2
  • $\begingroup$ were you able to solve it? $\endgroup$
    – Harry McKenzie
    Commented Jul 7, 2022 at 6:26
  • 1
    $\begingroup$ deselect and then manually figure out which vertices need to be selected. I made a second post where I explain my current solution. I wanted to know if there is a better way to select these vertices, but it seems like Blender just doesn't save the info about selected vertices anywhere. blender.stackexchange.com/questions/267973/… $\endgroup$
    – J.Doe
    Commented Jul 8, 2022 at 0:17

0

You must log in to answer this question.

Browse other questions tagged .