1
$\begingroup$

I'm new to Blender.I code an python script to learn bridge edge loop but something strange happened.

I'm trying the following steps

  1. select a circle of vertices
  2. use bpy.ops.mesh.duplicate() to duplicate the selected vert and move the duplicate to another position
  3. use vert.select_set(True) to select the two circle
  4. use bpy.ops.mesh.bridge_edge_loops() to bridge

4th step warning that "Select at least two edge loops",but if i execute step4 for the second time or do any operation before step4 ,it works

I want to know why this result occurred

enter image description here

$\endgroup$
1
  • $\begingroup$ most likely because vert.select_set(True) won't do in this context. As you're using bpy.ops, still use it to select: bpy.ops.mesh.select_all(action='SELECT'). If that does not fit with what you want, consider using a bmesh instead docs.blender.org/api/current/… $\endgroup$
    – lemon
    Commented Jan 15 at 8:26

1 Answer 1

2
$\begingroup$

bpy.ops relies on current selections and may change this selection.

This is probably what occurs when you run the script the first time.

In order to avoid that (and for performance reasons), you can use bmesh and bmesh.ops instead.

In edit mode, the following script will use the selected edges in order to extrude them and translate the extrusion along Z axis.

import bpy, bmesh

# ! will work in edit mode only !

# get the edited object
o = bpy.context.object

# create a bmesh from the object mesh
bm = bmesh.from_edit_mesh(o.data)

# extrude from the selected edges
ret = bmesh.ops.extrude_edge_only(bm, edges=[e for e in bm.edges if e.select])

# the previous result contains a 'geom' item that corresponds to the created geometry
# as this geometry contains verts, edges and faces, we keep only the vertices...
new_verts = [v for v in ret['geom'] if isinstance(v, bmesh.types.BMVert)]

# ...in order to translate them
bmesh.ops.translate(bm, verts=new_verts, vec=(0.0, 0.0, 1.0))

# set back what we did into the object mesh
bmesh.update_edit_mesh(o.data)
$\endgroup$
1
  • $\begingroup$ o, thanks. it works $\endgroup$ Commented Jan 16 at 1:41

You must log in to answer this question.

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