I essentially want to put a fence up around the edge of my object, is there a way I can select all vertices with 3 edges connected to it?
for vertex in object:
if vertex.connectededges == 3:
select
In your example, the 4 corners wouldn't get selected because they are connected to 2 edges.
However there is a handy operator with SHIFT + G or Select>Select Similar then "Amount of connecting edges"
Alternatively, if used in a script, you can use the operator :
bpy.ops.mesh.select_similar(type='EDGE', threshold=0.01)
But you need to first select some vertices.
If you can't select the vertices before running your script, use this :
import bpy
import bmesh
mesh = bpy.context.object.data # Get selected object's mesh
bm = bmesh.from_edit_mesh(mesh)
# Create new edit mode bmesh to easily acces mesh data
for v in bm.verts:
v.select_set(len(v.link_edges) in (2,3))
# Select all vertices that have 2 or 3 links and deselect the others
bmesh.update_edit_mesh(mesh) # Transfer the data back to the object's mesh
ob.select_set
if it is to become default and setting via v.select = True
is going to be phased out. Accidentally reverted to old ways in my answer lol.
$\endgroup$
Commented
Apr 9, 2020 at 13:28
Boundary edges
I essentially want to put a fence up around the edge of my object
IMO Simplest here to select edges that are boundaries, ie are connected to only one face.
import bpy
import bmesh
ob = bpy.context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)
for e in bm.edges:
e.select = e.is_boundary
bmesh.update_edit_mesh(me)
The vertex selection is implied by the edges. .. which is why I could have used
e.select_set(e.is_boundary)
BMEdge.select_set(select):
Set the selection. This is different from the select attribute because it updates the selection state of associated geometry.
Although in this case I'm of the belief that the verts of an edge are selected with the edge. So
verts = set(v for e in boundary_edges for v in e.verts)
will be same as selected verts.
v for v in bm.verts if v.select
Using the bmesh to extrude those edges.
Rather than selecting the edges, can instead feed them directly into bmesh operators. For the example below the vertices created as a result of extruding boundary edges are fed into transform operator, and moved up one in Z.
Result on 10 x 10 default grid
Notice newly created geometry added with bmesh is unselected by default. Run both these scripts below in edit mode.
import bpy
import bmesh
from bmesh.types import BMVert
from mathutils import Matrix
ob = bpy.context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)
bmesh.ops.transform(
bm,
verts = [
e for e in
bmesh.ops.extrude_edge_only(
bm,
edges=[e for e in bm.edges if e.is_boundary],
)["geom"]
if isinstance(e, BMVert)
],
matrix=Matrix.Translation((0, 0, 1)),
)
bmesh.update_edit_mesh(me)
Sure you can.