How to get a normal out of an edge?

Hello everyone,

I’m trying to learn some python coding. I’ve managed to make some progress but need to do something that I can’t see how.

I’m trying to generate an object on every edge of another object.
As an example, I can get the center of every edge on a mesh and generate a plane on edge’s center but further more I want to scale and rotate that plane along the edge, pointing up.

Searching google
I understood that I need more constraint while getting a normal vector out of an edge. Just two vertex positions are not enough. Also, I know it is OK for me to generate the plane meshes pointing up in world space. Is that enough!?!

bpy.ops.transform.rotate() gets a value and an axis…that makes me confused. I can not rotate the generated meshes as I want in my script.

I would really appreciate if somebody can help me.

Edit: I’ve added 3 screenshots to illustrate what I’m trying to achieve.



1- edge’s transform orientation is in local mode and Z is pointing up (what I need).


2-edge’s transform orientation is in Normal mode and Y is what I need.


3- Manually placed example plane for illustration.

hi, the main problem is that you don’t have the enought constrainsts

actually a initial solution is thinking in 2D as http://blender.stackexchange.com/questions/10805/how-to-duplicate-and-move-a-selected-edge-in-normal-direction

here a code example:

import bpy, bmesh
print("*"*50)
obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)


vo1, vo2 = [v for v in bm.verts if v.select]
dist = 0.5
n = (vo1.normal + vo2.normal) * dist
co1 = vo1.co + n
co2 = vo2.co + n
co3 = vo1.co - n
co4 = vo2.co - n


v1 = bm.verts.new(co1)
v2 = bm.verts.new(co2)
v3 = bm.verts.new(co3)
v4 = bm.verts.new(co4)
face = bm.faces.new((v1, v2, v4, v3))




#update normal in face
vo1.select=False
vo2.select=False
face.select = True
bpy.ops.mesh.normals_make_consistent(inside=False)


bmesh.update_edit_mesh(obj.data)



I think you can continue from here

best

Thank you YHOYO for the answer, i really appreciate you taking the time to answer.

Although your script works as intended It seems I was not able to clearly ask my question. Generating a plane was just as an example. I actually want another object to rotate and scale along an edge, that’s why I’m trying to use the " bpy.ops.transform.rotate() "

Also your script doesn’t help if a vertex is shared in multiple edges and vertices are placed in different Z positions (not flat)

One thing I can do is, I can take the generated planes face normal and rotate my object using that. Although not optimal, it can work.

Thanks again