I am brand new to Python, and cobbling things together from various sources, so I have next to NO idea what works, what doesn't work, or WHY things work.
I'm creating a script to apply a mirror modifier, then split the object into its two sides. I'm using two slightly different routines depending on whether it is one symmetrical object with a center line, or two mirrored objects with no connected geometry.
When I used this code, it worked:
mesh = ob.data
bm=bmesh.from_edit_mesh(mesh)
bpy.ops.mesh.select_mode(type='VERT')
vtest = False ##see if we can select side of active
for vert in bm.verts:
if(vert.co[0] == 0):
vert.select = True
bm.select_history.add(vert)
vtest = True
break
if(vtest): ## select side of active and part
bpy.ops.mesh.select_axis(sign='NEG')
bpy.ops.mesh.select_mode(type='FACE')
bpy.ops.mesh.separate(type='SELECTED')
However, if I selected the vertices in a loop and tried to switch to face mode it dropped the selection.
else:
for vert in bm.verts:
if(vert.co[0] <0):
vert.select = True
bpy.ops.mesh.select_mode(type='FACE')
bpy.ops.mesh.separate(type='SELECTED')
This threw the error 'no selection.' and if I stopped the script just before the FACE selection mode switch, the mesh was in edit mode, all the vertices on the left side were selected, and if I then clicked face select mode, everything would be deselected.
I can't explain that.
The code that I finally got to work is BS and i'd like to know what fifty things I did wrong.
bm.select_mode = { 'FACE' }
bmesh.update_edit_mesh(ob.data)
bpy.ops.object.mode_set(mode = 'OBJECT', toggle = False)
bpy.ops.object.mode_set(mode = 'EDIT', toggle = False)
bpy.ops.mesh.select_mode(type='FACE')
If I leave out any of those lines, it fails.
My BASE question is: why can I select vertices using the 'select side of active' command, then swap into face mode and convert the selection to faces but if I select the vertices myself in a loop and switch, it drops them?