mesh fabrication

fabricating other objects

material slots

animation and fcurves

incorporating python libraries


shape keys

animating curve bevel


UV layers



video sequence editor (VSE)

images and textures

analytic geometry

node trees


# for

__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
        return v1,v0

def mission1(obj, axis, len):

    bm = bmesh.from_edit_mesh(

    # collect a set of all the vertices from all selected edges (without duplicates)
    verts = set()
    for edge in bm.edges:

    # 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 = + 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:
            v0,v1 = guess_edge_order(bm, edge)
            v2 = newverts[v1.index]
            v3 = newverts[v0.index]
   [v0, v1, v2, v3] )

    # if we don't do this, it will look silly in the editor, and maybe even cause problems during render

    # apply all the changes we made back to to the target mesh data
    bmesh.update_edit_mesh(, destructive=True)


obj = bpy.context.active_object
scn = bpy.context.scene
# which custom orientation are we using?
orientation = scn.orientations['Face']

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.