```# for http://blender.stackexchange.com/questions/41281/blender-function-to-transform-a-selected-edge-along-a-custom-axis __author__ = 'thoth' import bpy import bmesh def guess_edge_order(bm, edge): """ We need to create a new face, but if that face is going to have a normal consistent with an adjacent face we need to choose the order of the vertices carefully. """ v0 = edge.verts v1 = edge.verts if len(edge.link_faces) != 1: # it is going to be non-manifold. balls! return v0, v1 face = edge.link_faces nverts = len(face.verts) i0 = [ i for i in range(nverts) if face.verts[i].index == v0.index] i0 = i0 #print(["indices", i0, face.verts[i0], face.verts[i1], i1]) i1 = (i0 + 1)% nverts #print(["next", face.verts[i1] , "==", v1]) # does the polarity of this edge match the order of the vertices on the face? if (face.verts[i1].index != v1.index): return v0, v1 else: return v1,v0 def mission1(obj, axis, len): bm = bmesh.from_edit_mesh(obj.data) # collect a set of all the vertices from all selected edges (without duplicates) verts = set() for edge in bm.edges: if edge.select: verts.add(edge.verts) verts.add(edge.verts) print(verts) # create new vertices "extruded" from the vertices of all the selected edges and # stash them in a hash so we can map from the old vertex to its extruded partner newverts = {} for v in verts: v2 = bm.verts.new( v.co + axis*len) newverts[v.index] = v2 # for each selected edge create a new face from the original edge plus the extruded vertices for edge in bm.edges: if edge.select: v0,v1 = guess_edge_order(bm, edge) v2 = newverts[v1.index] v3 = newverts[v0.index] bm.faces.new( [v0, v1, v2, v3] ) # if we don't do this, it will look silly in the editor, and maybe even cause problems during render bm.normal_update() # apply all the changes we made back to to the target mesh data bmesh.update_edit_mesh(obj.data, destructive=True) # # # obj = bpy.context.active_object scn = bpy.context.scene # which custom orientation are we using? orientation = scn.orientations['Face'] x_axis=0 y_axis=1 z_axis=2 m1 = obj.matrix_world.to_3x3().inverted() # this is what we need to map from world space to object space m2 = orientation.matrix.transposed() # we transpose this so we can extract a column global_axis = m2.row[z_axis] # this is the custom orientation axis we want in global space axis = m1* global_axis # now we have the necessary extrusion vector in the object's local coordinate space if True: print (m1*m2.row[x_axis]) print (m1*m2.row[y_axis]) print (axis) mission1(obj, axis, 1.5) """ p_w = m * p p2_w = p_w + l*d p2_w = m*p + l*d mi * p2_w = im*m*p + im*l*d mi * p2_2 = p + im*d*l """ ```

Syntax highlighting by Pygments.