0
$\begingroup$

My goal here is to select three vertices and manually create a face using bpy.ops.mesh.edge_face_add(). However, when I run the following code, no vertices are actually selected. I have been using this (How do I select specific vertices in blender using python script?) StackExchange question and answer to no avail. Sometimes my script will select one vertex, sometimes it will not. It never selects more than one. current_min_vert and the others are MeshVertex class objects, and should be equivalent to obj.data.vertices[n], where 'n' is any prescribed integer. Here is the code:

# Join meshes into one        
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.join()

# Set selection mode
bpy.ops.object.mode_set(mode = 'EDIT') 
bpy.ops.mesh.select_mode(type="VERT")
bpy.ops.mesh.select_all(action = 'DESELECT')

# Select vertices to form a triangle
bpy.ops.object.mode_set(mode = 'OBJECT')
current_min_vert_copy.select = True
current_min_vert.select = True
current_max_vert.select = True
bpy.ops.object.mode_set(mode = 'EDIT')

The following image is my end goal. The top right vertex is current_min_vert_copy, the bottom right is current_min_vert, and the bottom left is current_max_vert.

The end-goal.

Any assistance is greatly appreciated.

$\endgroup$
3
  • 1
    $\begingroup$ Where do you define current_min_vert? The problem might lie here. $\endgroup$ Commented Oct 12, 2023 at 19:35
  • $\begingroup$ @BlenderEnthusiast I define my current_max and current_min verts while looping through all the vertices of my mesh object. When I print out the value of current_min_vert and others, a MeshVertex class object is printed to the command window, indicating that Blender probably recognizes it as a vertex of my mesh. current_max = np.abs(vertex.co.x); current_max_vert = mesh_object.vertices[i] EDIT: My for loop was ill-formatted, so I replaced it with a simpler version. $\endgroup$
    – Frances
    Commented Oct 12, 2023 at 19:51
  • $\begingroup$ Please always provide a minimal working example, otherwise it's hard to give a definitive answer. $\endgroup$ Commented Oct 12, 2023 at 20:09

1 Answer 1

0
$\begingroup$

Blender Python objects are short-lived and can be invalidated by various things like ✲ CtrlZ undo or switching between Edit and Object modes…

Rather than assigning chosen vertices to your variables, assign their indices to your variables, and then change these lines:

current_min_vert_copy.select = True
current_min_vert.select = True
current_max_vert.select = True

to

me = D.objects["name_of_object"].data
me.vertices[current_min_vert_copy].select = True
me.vertices[current_min_vert].select = True
me.vertices[current_max_vert].select = True
$\endgroup$
1
  • 1
    $\begingroup$ Thank you so much, this worked! $\endgroup$
    – Frances
    Commented Oct 12, 2023 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .