hemming script: where to start?


i’m not a programmer (though i have done some scripting), and i don’t know Python or Blender’s version of it, but i’d like to be able to make a script that will add a hem of user defined thickness and width to clothes (any object with open edges, really). an edge or piping that goes up t from the normal and out w from the poly, then back down -t and in -w. looking at the scripts that come with Blender, i know this isn’t the simplest task and probably not where anyone would suggest starting. i figure it would be fine to start with an edge selected, but i still don’t know how to proceed doing this sort of thing. but i’m interested in where people would suggest starting since that’s my goal. i’ve just (as in yesterday) started looking at the included scripts, at the one starting tutorial i could find (which seems to be out of date, because it uses a class marked deprecated), and at the API docs. i’ve spent some time before that searching these fora, which is difficult because there seems to be no way around or rather than and searching. i’m hoping someone can tell me something to focus my efforts, like what classes or functions to look at. i’d actually appreciate general advice of any kind.

thanks in advance.

To start with you need to know which vertices to operate on. You can do this by finding out which edges are only used in 1 face. To do this you loop through all faces and keep track of which edges they use. If an edge is only found once, it’s one we want to operate on, so get its vertices. Store these vertices in a list and you’re ready for the next step.

With this list you can calculate the postion where the new vertices should be inserted. You can do this by adding the values you want to extrude with to the vertex vector. Next up is actually adding these vertices to the mesh and creating faces using these vertices.

The final step is updating the mesh and redrawing the windows, so the changes actually show up.

Now let’s get you started:

import bpy
from Blender import *

# Get the current scene
sce = bpy.data.scenes.active
# Get the active object
ob = sce.objects.active
# Get the mesh data linked to this object
me = ob.getData(mesh=True)

The ‘me’ variable now holds the mesh data, like faces, edges and vertices.
Here’s a quick example that continues on the previous and prints the location of all vertices in the mesh:

for v in me.verts:
    print v.co

You’ll see that these locations are actually vectors, which has a great advantage: you can do vector math on them. So you can simply add a vector to them and get the new position as a vector.

I hope this gets you started. When (if) you run into any problems just tell me.
If you don’t really feel like writing this yourself, I might be able to do it for you, but an image which shows how exactly you would like to have the hem (including the thickness and width variables) would be appreciated in that case. I do have some idea of how you’d like to extrude the edge, but an image is usually much more clear.