import bmesh
bmesh.from_edit_mesh(bpy.context.edit_object.data).faces[1].select=True
It says python script fail
What should I do ?
import bmesh
bmesh.from_edit_mesh(bpy.context.edit_object.data).faces[1].select=True
It says python script fail
What should I do ?
This is how to create a new object and add the vertices in the verts list:
import bpy
import bmesh
verts = [(1, 1, 1), (0, 0, 0)] # 2 verts made with XYZ coords
mesh = bpy.data.meshes.new("mesh") # add a new mesh
obj = bpy.data.objects.new("MyObject", mesh) # add a new object using the mesh
scene = bpy.context.scene
scene.objects.link(obj) # put the object into the scene (link)
scene.objects.active = obj # set as the active object in the scene
obj.select = True # select object
mesh = bpy.context.object.data
bm = bmesh.new()
for v in verts:
bm.verts.new(v) # add a new vert
# make the bmesh the object's mesh
bm.to_mesh(mesh)
bm.free() # always do this when finished
This is how to alter an existing mesh:
import bpy
import bmesh
verts = [(1, 1, 1), (0, 0, 0)] # 2 verts made with XYZ coords
mesh = bpy.context.object.data
bm = bmesh.new()
# convert the current mesh to a bmesh
bm.from_mesh(mesh)
for v in verts:
bm.verts.new(v) # add a new vert
# make the bmesh the object's mesh
bm.to_mesh(mesh)
bm.free() # always do this when finished
As for selection:
import bpy
import bmesh
mesh = bpy.context.object.data
bm = bmesh.new()
# convert the current mesh to a bmesh
bm.from_mesh(mesh)
# must run this so we can use indexing on the faces
bm.faces.ensure_lookup_table()
# "select" the 0th face by setting its select property to True
bm.faces[0].select = True
# make the bmesh the object's mesh
bm.to_mesh(mesh)
bm.free() # always do this when finished
# go back to edit mode to see the selection
bpy.ops.object.mode_set(mode='EDIT')
To test this:
bm.from_mesh(). To make it "live" in edit mode use bmesh.from_edit_mesh(mesh) and bmesh.update_edit_mesh(...) to update changes to mesh without the need to toggle modes.
– batFINGER
Nov 30 '16 at 14:45
bmesh.from_edit_mesh(...)Use this if you are going to make an edit mode tool. A call to bmesh.update_edit_mesh(...)will show your changes "live". Otherwise usebm = bmesh.new()and load the mesh withbm.from_mesh(...). Oh andimport bpy` too, what exactly is the error message? – batFINGER Nov 30 '16 at 14:36