cloning
link-mesh-array.py
link-mesh.py

mesh fabrication
staircase.py
triangle-donut.py
vertexAccumulator.py
randomSquareArray.py
meshFromBathymetry.py
cylinders-from-list-of-radii.py
binary-image-to-mesh.py
sphere-minecraft-schematic.py
spikify.py
add-to-mesh.py
mobius-strip.py
split-copy-mesh.py

fabricating other objects
create-text.py
text-from-file.py
create-camera.py
create-bezier.py
helix-bezier.py

material slots
cube-copy-blue.py
cube-turns-red.py
red-blue-per-object.py

animation and fcurves
csv-to-fcurve-loc-rot.py
csv-to-fcurve.py
pop-in-material.py
spike-wiggle-2.py
spike-wiggle.py
sweep-animate-size.py
animate-cycles-lamp-strength.py

incorporating python libraries
exec-text-library.py
exec-external-python.py
import-python.py

constraints
camera-track-object.py
text-track-camera.py

shape keys
explore-shape-keys.py
shape-key-fin.py
docking-tube.py

animating curve bevel
data-graph.py

drivers
scan-drivers.py
copy-drivers.py
driver-fin.py
driver-multi-chain.py

UV layers
barber-pole.py
expand-uv-to-fit.py
uv-from-geometry-cubic.py
flip-texture-v-coordinate.py

modifiers
hook-modifier-curve.py
rounded-prisms.py
make-tile.py
remove-action-modifiers.py

NLAs
explore-NLAs.py
spinning-frogs.py

video sequence editor (VSE)
create-vse-image-strips.py
slide-show.py
vse-strip-gap.py

images and textures
image-on-mesh.py
image-to-material-node.py
load-image-texture.py
texture-one-cube-face.py
condense-duplicate-images.py

analytic geometry
animate-random-spin.py
camera-cone-exp-2.py
camera-cone-exp.py
compute-circle-center.py
dihedral-angle-from-xy.py
extrude-edge-along-custom-axis.py
orientation-matrix.py
two-spheres.py
bezier-interpolate.py
rotate-to-match.py

node trees
change-diffuse-to-emission-node.py

etc
add-plane-from-selected-vertices.py
adjust-all-materials.py
all-nodes-cycles-materials.py
bit_shift.py
bone-orientation-demo.py
cannonball-packing.py
comb.py
convert-quaternion-keyframes-to-euler.py
copy-location-from-vertex-group.py
create-cycles-material.py
demonstrate-decomposition-instability.py
dump-point-cache.py
dump-screen-layout-info.py
expand-nla-strips.py
explore-edge-bevel-weight.py
find-action-users.py
find-green-rectangle.py
find-new-objects.py
fix-scene-layers.py
generate-makefile.py
link-external-data-blocks.py
list-referenced-files.py
material-readout.py
movie-card-stack.py
movies-on-faces.py
next-file-name.py
object-font-from-regular-font.py
operator-mesh-gridify.py
particle-animator.py
particle_loop.py
pose-match.py
pose-sequence-to-fbx.py
prepare-texture-bake.py
raining-physics.py
random-pebble-material.py
reverse-keyframes.py
scale-parallelogram.py
screenshot-sequence.py
select-objects-in-modifiers.py
select-vertices.py
shift-layers.py
snapshot-keyframes-as-mesh.py
sphere-project-texture.py
squish-mesh-axis.py
subdivide-fcurve.py
thicken-texture.py
transform-selected.py
voronoi-madness.py

# 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[0]
    v1 = edge.verts[1]
    if len(edge.link_faces) != 1:
        # it is going to be non-manifold.  balls!
        return v0, v1

    face = edge.link_faces[0]
    nverts = len(face.verts)

    i0 = [ i for i in range(nverts) if face.verts[i].index == v0.index]
    i0 = i0[0]
    #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[0])
            verts.add(edge.verts[1])
    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
"""

Blender python API quick-start

Syntax highlighting by Pygments.