0
$\begingroup$

I've a mesh (a foot sole) and I would like to select 2 vertex of this mesh and create a plane.

I select the two vertex (V1 et V2) I select the two vertex

Then a plane is automatically added. Vertex of the plane are:

  • 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

enter image description here

Do you have any idea?

Thanks,

Maxime

$\endgroup$
2
  • $\begingroup$ Should this new plane be an independent object? Should it be a polygon inside the mesh that you are currently editing? $\endgroup$
    – Mutant Bob
    Apr 12, 2017 at 21:07
  • $\begingroup$ I should be independent because I will apply a modifier on it and on the object $\endgroup$
    – Maxime
    Apr 13, 2017 at 17:19

1 Answer 1

0
$\begingroup$

A second draft would be

import bpy
import bmesh

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()

The original code which adds geometry to the original object can be found as mission1() in my cookbook at http://web.purplefrog.com/~thoth/blender/python-cookbook/add-plane-from-selected-vertices.html .

$\endgroup$
2
  • $\begingroup$ Thank you for the example. It's working fine ! What if I want to have a separate object for the plane? In fact, afterwards, I'll apply a modifier with the sole and the plane (Already done ). Thanks $\endgroup$
    – Maxime
    Apr 13, 2017 at 15:37
  • $\begingroup$ I have adjusted my answer to create a separate object. $\endgroup$
    – Mutant Bob
    Apr 13, 2017 at 19:22

You must log in to answer this question.

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