Skip to content

Instantly share code, notes, and snippets.

@semagnum
Created January 25, 2023 21:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semagnum/c95a0cd87a15b34cc04bd5c3efc6c2d8 to your computer and use it in GitHub Desktop.
Save semagnum/c95a0cd87a15b34cc04bd5c3efc6c2d8 to your computer and use it in GitHub Desktop.
Extracts mesh data to be used for mesh.from_pydata()
import bpy
from mathutils import Vector
# prereq: go into your object's edit mode
context = bpy.context
mesh = context.edit_object.data
verts = [v.co for v in mesh.vertices]
edges = [[v for v in e.vertices] for e in mesh.edges]
faces = [[v for v in p.vertices] for p in mesh.polygons]
print(verts)
print(edges)
print(faces)
bpy.ops.object.editmode_toggle() # back to object mode
mesh = bpy.data.meshes.new("myBeautifulMesh") # add the new mesh
obj = bpy.data.objects.new(mesh.name, mesh)
col = bpy.data.collections["Collection"]
col.objects.link(obj)
context.view_layer.objects.active = obj
mesh.from_pydata(verts, edges, faces)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment