Problem with a simple bmesh script

Hello. I’m new to blender python coding, and Im having trouble with a simple script, can you help ?

What am I trying to do ?
To duplicate the selected faces of a mesh and create a new object with them

import bpy, bmesh

#getting the object to where faces copy from
obj = bpy.context.object

#Im going to work with bmesh, so
#mesh is the source obj mesh
#out is the output where I store the faces
mesh = bmesh.from_edit_mesh(
out =

#list to store selected faces
myfaces = []

#loop through mesh and get selected faces
for f in mesh.faces:
#loop through selected faces list and input them in the output mesh
for f in myfaces:

#Creating the mesh in blender data
outMesh ="New Mesh")

#transfering bmesh data to mesh

#Creating obj and linking to outMesh
outObj ="New Obj",outMesh)

#linking obj to scene

I keep getting the error: “ValueError:…): 0 (BMVert) is from another mesh”. I don’t know what that means at all.

To add vert to “out” you have to create NEW verts on it. and copy parameters from initial vert (.co)
You can not assign objects from one bmesh to another, you have to create object “clone” with secondary bmesh