2
$\begingroup$

I want to make a new object out of selected verts via Bmesh

import bpy
import bmesh

object = bpy.context.object
bm = bmesh.from_edit_mesh(object.data)
bmesh.ops.duplicate(bm, geom=[v for v in bm.verts if v.select])

name = 'Object'
mesh = bpy.data.meshes.new(name)
bm.to_mesh(mesh)
mesh.update()
bm.free()

object = bpy.data.objects.new(name, mesh)
bpy.context.scene.collection.objects.link(object)
$\endgroup$

1 Answer 1

1
$\begingroup$

The easiest way to do this is to use the bmesh copy operator. Here's an example:

import bpy
import bmesh

original = bpy.context.object
if original.mode == 'EDIT':
    bm = bmesh.from_edit_mesh(original.data)
else:
    bm = bmesh.new()
    bm.from_mesh(original.data)
    
bmCopy = bm.copy()

meshCopy = bpy.data.meshes.new('meshCopy')
objectCopy = bpy.data.objects.new('objectCopy', meshCopy)

bmCopy.to_mesh(objectCopy.data)
bmCopy.free()

bpy.context.collection.objects.link(objectCopy)

Note that the meshes will end up identical but any object properties will not be copied.

$\endgroup$

You must log in to answer this question.

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