# http://blender.stackexchange.com/questions/77626/python-create-a-plane-from-selected-vertex
import bpy
import bmesh
def mission1():
bm, new_coords, obj = coordinates_for_new_plane()
new_verts = [
bm.verts.new( v ) for v in new_coords
]
f1 = bm.faces.new( new_verts)
bmesh.update_edit_mesh(obj.data)
obj.data.update()
def coordinates_for_new_plane():
obj = bpy.context.active_object
if bpy.context.mode != 'EDIT_MESH':
raise BaseException("should be in edit mode")
bm = bmesh.from_edit_mesh(obj.data)
(v1, v2) = [v.co for v in bm.verts if v.select]
new_coords = [
[v1.x, v1.y - 100, v1.z + 10],
[v1.x, v1.y - 100, v1.z - 10],
[v2.x, v2.y + 100, v2.z - 10],
[v2.x, v2.y + 100, v2.z + 10],
]
return bm, new_coords, obj
def mission2():
bm, new_coords, obj = coordinates_for_new_plane()
name = "platypus"
mesh = bpy.data.meshes.new(name)
faces = []
faces.append( [0,1,2,3])
mesh.from_pydata(new_coords, [], faces)
o2 = bpy.data.objects.new(name, mesh)
scn = bpy.context.scene
scn.objects.link(o2)
o2.location = obj.location
o2.rotation_euler = obj.rotation_euler
o2.rotation_quaternion = obj.rotation_quaternion
o2.scale = obj.scale
#
#
#
mission2()
|
Blender python API quick-start
Syntax highlighting by Pygments.