Question

In blender i can make a mesh "me" from a list of vertices like that:

me = bpy.data.meshes.new("name") 
me.from_pydata(vertices,[],[])

But this function does not exist for a bmesh. What i would like to do is

bme=bmesh.new()
bme.from_pydata(vertices,[],[])

How can i achieve this?

Was it helpful?

Solution

A slightly modified version of the bmesh template would give you

import bpy
import bmesh

myvertexlist = [[2,2,2],[4,4,4],[6,6,6],[8,8,8]]

# Get the active mesh
me = bpy.context.object.data

# Get a BMesh representation
bm = bmesh.new()   # create an empty BMesh
bm.from_mesh(me)   # fill it in from a Mesh

# Modify the BMesh, can do anything here...
for newvert in myvertexlist:
    bm.verts.new(newvert)

# also add bm.edges and bm.faces

# Finish up, write the bmesh back to the mesh
bm.to_mesh(me)
bm.free()  # free and prevent further access
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top