Identifying and Selecting specific vertices

The ONLY thing on the page is a cube that’s been poked “Alt-P”


If I run the code below in python console, I get a list of verts.

>>> current_object = bpy.context.active_object
>>> [i.index for i in current_object.data.vertices if i.select]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

If I run this code (pulled from the info panel):

import bpy

bpy.ops.mesh.primitive_cube_add()
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.poke()
bpy.ops.mesh.select_all(action='TOGGLE')

#Select ANY Center Vert then run "cube_star_02.py" 

Select ANY Center Vert and then run:

import bpy

#After Select Center Vert

bpy.ops.mesh.select_similar(type='FACE', threshold=0.01)
bpy.ops.transform.resize(value=(3.53695, 3.53695, 3.53695), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.inset(thickness=0.291296, use_individual=True)
bpy.ops.mesh.delete(type='FACE')
bpy.ops.object.editmode_toggle()

I get the desired outcome.

This could just as easily (or maybe not, given what may be involved) be one program if not for the fact that
I haven’t been able to figure out what to do with the identified verts to be able to determine WHICH are the Center Verts and HOW to select them.

There may be an answer somewhere, but, either it speaks to my specific problem and I just don’t know enough to know it (entirely possible) or it hasn’t been specifically addressed because it hasn’t been specifically asked.

This one looks to be fairly simple. It’s the only object on the page. It’s a basic object (Cube). Other than that I’m stumped.

How do I

  1. Identify the center verts
  2. Programmatically select them

Thanx

Update:

Ok, I found this:

import bpy
import bmesh


index = 0 # here the index you want select please change 

obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)

vertices= [e for e in bm.verts]
oa = bpy.context.active_object

for vert in vertices:
    if vert.index == index:
        vert.select = True
    else:
        vert.select = False

bmesh.update_edit_mesh(me, True)

Here:

How could I select a vertex by its id?

Trial and error identified the verts as 8 - 13.

The combined code is here:


import bpy
import bmesh

indices = [8, 9, 10, 11, 12, 13] 

bpy.ops.mesh.primitive_cube_add()
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.poke()
bpy.ops.mesh.select_all(action='TOGGLE')

obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)

vertices= [e for e in bm.verts]
oa = bpy.context.active_object

for vert in vertices:
    if vert.index in indices:
        vert.select = True
    else:
        vert.select = False

bmesh.update_edit_mesh(me, True)  

bpy.ops.mesh.select_similar(type='FACE', threshold=0.01)
bpy.ops.transform.resize(value=(3.53695, 3.53695, 3.53695), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.inset(thickness=0.291296, use_individual=True)
bpy.ops.mesh.delete(type='FACE')
bpy.ops.object.editmode_toggle()

This takes care of the “how to select them programmatically” part.

Still, trial and error is not the best way to go about this. Here, I’m only dealing with 6 out of 14 verts.

It would be nice® to be able to have a way to identify them, even if only selecting them first and having python
report out their ids.

Here is one way to select only the poked verts:

import bpy

bpy.ops.mesh.primitive_cube_add()
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.poke()
bpy.ops.mesh.select_all(action=‘TOGGLE’)
bpy.ops.mesh.edges_select_sharp()
bpy.ops.mesh.select_all(action=‘INVERT’)

Yup, SterlingRoth, that works as well.

Thanx


import bpy


bpy.ops.mesh.primitive_cube_add()
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.poke()
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.edges_select_sharp()
bpy.ops.mesh.select_all(action='INVERT')

bpy.ops.mesh.select_similar(type='FACE', threshold=0.01)
bpy.ops.transform.resize(value=(3.53695, 3.53695, 3.53695), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.inset(thickness=0.291296, use_individual=True)
bpy.ops.mesh.delete(type='FACE')
bpy.ops.object.editmode_toggle()