Skip to content

He runs :)

More information about how this latest version of the chair was built, in an upcoming post.

Meanwhile, download the 3D printable files here.


Freedom Farm Animation

I had a chance to do a short 10 second animation recently for the Freedom Farm initiative, a non-profit aiming to establish the first farm animal sanctuary in Israel, with a museum and education center.

This was the opening sequence for a promotional video, which introduces viewers to the farm and why it’s so important.

I had very little time to do this, as work is pressing, but I think it came out alright even if I’d add and improve a gazillion things if I had the time.

Everything was modeled in Blender and the animation was rendered in Cycles.

I used this nice grass made by blendswap user einarparker, but modeled the rest myself. A particle hair system was used to distribute the grass on the hills (which were created with the landscape generator addon and some sculpting).


Grass object group used for the particle system. Original grass provided by einarparker (downloaded from

I also used a few of the awesome textures Pixar released recently to the public, and some image textures I took myself. Spec, normal and AO maps were generated using the free and wonderful AwesomeBump.

Awesome Bump texturing

Generating AO, normal, spec and cleaned diffuse maps from a single image with the incredible AwesomeBump – easy, quick and looks great!

For the animation (which was simple camera movement only), I added some subtle camera shake as suggested by Andrew Price (Blender Guru).

I made the mistake of rendering the sky separately from the rest, which looked far less good than it would otherwise. I used some filtering in compositing to mix the two, but it shows if you look carefully (mild blur and a weak halo around the edges where the sky meets the foreground). If I had time I’d add a whole lot more detail, add more terrain in the far background, replace the sky, use a procedural texture for the wood fence (the repeats show and it’s annoying!) and improve the lighting.


Node setup used for compositing. The sky and the foreground came from different image sequences, rendered separately (big mistake), and blended back together with some subtle edge blurring. I also added a vignette and an animated blur vignette to fake DOF when close to the grass (accomplished with a simple fast gaussian filter applied via a circular black and white gradient, with the factor animated).

Rendering took around 35 hours in total for 250 frames, with my 2GB Nvidia GTX660 GPU.

Complaints and perfectionism aside, this was a really nice foray back into 3D animation from my daily coding routine. In the next few weeks I’ll get to follow it up with an internal architectural visualization of the farm’s museum, something I hope to do in a higher standard and perhaps also generate an interactive “playable” version for web interaction.

Other stuff

The cat’s wheel harness is progressing too, and a much improved new version simply needs integrated screw sockets on the aluminum frame. More updates about that soon.

Shiny new model almost ready for testing...

Shiny new model almost ready for testing…

I also got some comments and emails about some of my scripts that require updates and don’t work well with Blender 2.74. I’ll try to find time to handle these ASAP, which will probably be sometime during the next week or two.

Kitten wheel harness – part II

What a week. A week of many lessons learned.

5 faulty designs for the pipe connector until I finally found one that will hold the pipes in place and won’t break.

A failed attempt to put the harness on the kitten, giving some clues to required (but yet missing) body supports.

And the best lesson – a visit to a vet specializing in rehabilitation medicine.

In case you have no idea what I’m talking about, you should probably read part I.

Problems with the 3D printed pipe connector and how I finally solved ’em

The wheel harness’ frame has 3 pipes connected to each other, with two longitudinal pipes attached to one transverse pipe.

The aluminum pipes’ round profile makes them quite strong for their weight, but the roundness also makes it harder to hold the pipes in place. The simplest way to connect the pipes is to screw or weld them to each other, but that renders the connection permanent and non-adjustible.

My aim is to create an adjustible wheel harness that can fit cats and dogs of various sizes, so I designed an adjustable 3D printed connector that squeezes on the pipes to hold them in place.

I had some experience using this method with aluminum connectors and it worked quite nicely. Aluminum seemed like overkill here though, since the frame won’t have to withstand too much force. In addition, it was quite difficult to make that connector, and required a mill and a lathe (not your everyday DIY equipment).

3D printing to the rescue. I designed a minimalistic connector, and Inspired by some other designs I saw online, I added a socket for embedding bolts in the plastic.

Connector Design #1

However, this connector broke rather quickly. It could hold the pipes in place rather well, but preventing them from rotating required a much stronger grip, and trying to tighten the bolt to accomplish that broke the connector.

Unfazed, I changed the design and tried adding thickness, widening the contact area between the pipe and connector and making the gap between the “lips” larger to increase the pressure on the pipe. The design gradually improved but nothing worked quite well enough, until I made a rather rigid, blocky design (leftmost in the image below).


Initially I was pretty happy with it. It held the pipes beautifully in place, and the pipes did not budge in any direction. I could apply quite a bit of pressure by tightening the nut and bolt and it didn’t break. Success? almost. It did have one major flaw…


The rigid structure proved to be a double edged sword, and it made the connector fragile in a particular axis. When I pushed a pipe inside forcefully or yanked it sideways so that it applied pressure outwards, cracks showed up and the whole thing could split into two pieces.

Further investigation showed that the very nature of 3D printing was to blame here. The piece’s weakest point was the adhesion between layers themselves. The vertical layering weakened the structure and when enough force was applied, the layers just separated and the whole structure split.

The solution – rotating the whole structure by 45 Degrees

After consulting with my start-up partner Dudu, he suggested to change the direction of the layering, by rotating the whole piece by 45 degrees. This way, the vertical layers will not be parallel to the forces applied by the pipe to the connector, and the structure will maintain its rigidity without sacrificing cohesivity.

While it’s easy to rotate the part in 3D software, printing the rotated piece is another matter. From a nice flat piece, I now had an overhanging unsupported mass. I print with Repetier and Slic3r, and the latter never seems to generate stable supports. You can see the automatic supports it generated below:


I tried to print this, but the supports didn’t stick to the bed or just collapsed way before they even had to suport anything, and I was forced to terminate the print job.

You know what they say, “if you want something done, do it yourself”. So I generated my own supports in Blender, with a column field that provided excellent support but was a pain to extract the pieces from


It took me around 10 minutes per piece and a scalpel, rotary tool, scissors, wire cutter, electric drill and pliers to clear up all the supports, but the piece was perfect – didn’t break and withstood enough pressure to hold the pipes in place beautifully. A reliable solution at last!


It took a lot of trial and error until I found a design (and print method) that works reliably, but I’m happy with the result (rightmost above).

Fitting the harness to the kitten (or rather trying to)

There’s one element crucial to the harness that’s almost invisible in all the images you can see online, unless you know what to look for.

When animals are strapped to the harnesses, you can easily see the frame, the wheels, and the front harness. Sometimes you can even see a belly support strip. But one of the most important parts is the rear harness or saddle, and since its integral to the frame and lies flat, it’s really hard to spot.

Which is why I didn’t really include one in my design…


Without a rear harness, the kitten couldn’t use the cart at all, and the whole thing just anchored him to the floor. Poor thing mewed in frustration and I felt a pang of premature desparation. First time that happened, I didn’t even know that was the reason it failed, and suspected the frame was simply too short. While that was true, the real insight came later when we went to visit a specialist vet, who’s an expert in rehabilitation at “Ha Kfar Ha Yarok” veterinary hospital.

The vet loved my design and the lightness of the frame compared to the Walking Wheels commercial harness they offer to clients at the clinic. But she immediately pointed out the lack of a rear harness.

At first I was flummoxed, but then I saw her demonstrate how to train the kitten in spinal walking using a wiry front harness as a rear harness. I suggested we try to use it for the wheel cart, and it was a pretty sound solution that held Benji’s hind legs nicely in place.

But then an additional problem manifested itself – the wheels were to low, even extended to the full height (around 15cm above ground) using my adjustable design.

The harness has to lie straight across the cat’s body, in order to avoid applying pressure on his back, which means the wheels have to be precisely the right height.

Since I had no way of adding height without preparing longer aluminum bars for the wheels, it was game over for the night. To see how it’s supposed to work, we strapped the commercial harness on Benji, but it was way to big for him so it didn’t help much except for giving me a few ideas for improving the usability of my design.


The Walking Wheels harness is pretty awesome. It’s fully adjustible, sturdy and has great build quality. The only downsides are that It’s pretty heavy and quite expensive (250-500$ if you buy it directly from them). I guess the quality of the product justifies the price, but some people just can’t afford it, and it doesn’t fit small cats. Another proof that a cheap, versatile and effective design is in needed.

What’s next

Since I posted about the DIY harness on Facebook, I got 3 more requests for helping another disabled cat and two disabled dogs. One dog needs a front harness, which is a completely different matter.

But I shouldn’t get ahead of myself. After all, this harness is not yet finished. I still need to prepare longer bars for the wheels, and attach a permanent rear harness to the frame. Both tasks are pretty straightforward, especially since I’m not the one making the rear harness! A friend’s mother, an experienced seamstress, is making a beautiful rear harness for Benji.

Which makes me worry a bit about the simplicity of the DIY solution I’m trying to devise. If you need to find a seamstress to make a harness for you, in addition 3D printing and cutting and drilling into aluminum pipes and bars, it’s starting to get complicated.

But I believe I’ll be able to find a solution for this as well. I’ll try making the next rear harness myself, and to again combine readily available materials with 3D printing to keep it simple.

But first, I want to see Benji walk. Tomorrow I’ll be heading back to the makerspace to prepare the new wheels, and later try fitting the harness to Benji again. Hope I’ll have exciting news to share!

Kitten wheel harness – part I

A friend of mine recently found a home for a disabled kitten, whose hind legs are paralyzed.

The poor thing wants to play and move around like any other kitten, so he drags himself around with his forelegs. He doesn’t get far, and he scrapes and wounds his legs in the proces.

My friend posted on Facebook that she hopes to raise enough money to buy the critter a wheelchair, or more accurately a wheel harness.

But commercial harnesses are awfully expensive, so that prospect didn’t seem promising.

At work I’ve been working on a 3D printed armor for a child with Osteogenesis Imperfecta, a disease that causes bone malformation and frequent fractures. So I thought to myself, I have a 3D printer, why not build a wheel harness for the kitten and be done with it?


I did a quick google search with the search phrase “cat wheel chair”, and found lots of images, most of which seemed like improvized designs with huge heavy frames and wheels.

But one design caught my eye. It seemed quite elegant and minimalistic, and had the advantage of a lot of clearance and space between the wheels, which is important for avoiding low obstacles.

This seemed like something I can build. And while I’m at it, why not publish and release the 3D files so that anyone can build a cheap one too?

I also decided to make it adjustable, since the kitten will grow and need the harness to become longer and wider with time.

Materials and methods (and stuff)

After sketching around for a bit in Blender, I came up with this design. If it looks familiar, it’s because it’s an almost shameless copy of the one above, with a twist 😀

Cat Wheel Harness Initial Design

Cat model used for this illustration made by Gwinna, downloaded from Blendswap.

After completing the general design and having a 3D model to play with it, I went shopping. I bought an aluminum bar 20mm wide and 3mm thick (and 3m long, since they wouldn’t sell any less). And I also bought an aluminum pipe with a diameter of 8mm (and a 1mm thick wall), again 3m long. Each 3m piece cost around 35NIS (around 9$ / 8 EUR ).

I also bought a pair of wheels and screws for attaching them to the bar. The wheels have a diameter of 8cm and a nice almost “offroadish” tread. The pair cost 15NIS (4$ / 3.5 EUR).

The last item I needed to buy was the actual harness, so I went to the pet food store, and asked for the smallest dog harness they’ve got. This cost 40NIS (10.5$ / 9 EUR).

Now I needed to finalize and 3D print the connectors – two for connecting the longitudinal pipes and the transverse pipe, and another two for connecting the wheels to the longitudinal pipes. The remaining two pieces are for connecting the harness to the frame.

3D printing

I have a 3D printer at home for a few months now, and I haven’t used it nearly enough yet. The problem is finding interesting things to do with it, and I have lots of ideas, mind you, but most of them require more time than I actually have. The wheel harness was a wonderful use for the printer, and the first really useful thing I’ve done with it.

My printer is an open source Prusa i3 Hephaestos, which is a damn good printer kit that wasn’t easy to build (even though I built it during a short printer building course). Challenging though it was, it was well worth the cost and effort.

As I’m still something of a newb with hands on printing at home, I’ve been having trouble printing with ABS (heated bed and special sticker notwithstanding). So I decided to print the harness parts with the much friendlier white PLA I’ve got mounted on the printer.

Printing Parts for the Wheel Harness

This went along rather smoothly, except for the frustratingly difficult removal of the supports on the harness connector (the long round pieces in the middle). A Scalpel, pliers and scissors were used alternately until the damn thing agreed to come off.

Of course I had to reprint the whole bunch 3 times, because I discovered various bugs every time (bar canal too narrow, screw hole diameter too small, fragile parts, etc).  I adjusted the models after every test, and ended up with a design I’m happy with, until I can test it on the actual kitten and see if it actually works in real life.

Cutting, drilling and bending

I visited the local makerspace, XLN Tel-Aviv community laboratory, and used their disk saw, vise and drill press to cut the pipes and bar to the desired lengths, and to drill holes where needed.

I cut the pipes into 20cm, 15cm and 10cm pieces, and decided to try it first with two 20cm (length) pipes and one 15cm (width) pipe. The bar was cut into 16cm long pieces.

I drilled 6 holes every 1cm on the top 7cm of the bar, and another hole at the center of the bottom 2cm.

The vise and hammer came in handy for bending the bar into the desired shape. I bent the middle 7cm (after drilled bit at the top) in a ~30 degrees angle, then bent the bottom 2cm long bit back the opposite direction until it was parallel with the straight upper part.


The aluminum bar before bending and drilling a hole for the wheel at the bottom 2cm. This piece was discarded due to the appallingly inaccurate drilled holes (something that was avoided afterwards by making initial dents to guide the drill).


Assembly was pretty simple, and required only 4 X M4 nuts and bolts, and two sharp edged M5 screws. The bolts need to be rather short, around 10mm long. I didn’t have any short M4 bolts, so I used my rotary tool (Dremel copy) to cut ’em the 2cm long bolts I had. I used a pair of double edged velcro strips to attach the harness to the frame, and the rest was pretty straight forward, as the printed connectors do most of the work for you.

This is the result of all this work, and in a few days I’ll hopefully get to see if it actually works, and maybe give a little kitten his mobility back.

When I’ve fixed all the bugs with the design, I’ll release the 3D files and instructions so that anyone can make this cheap, quick wheel harness for their disabled pets.

This slideshow requires JavaScript.

Useless box build diary

First things first

First post since February. Heck, has it really been six months?!

Sorry for the delay, and for disappointing anyone who’s been expecting new stuff regarding Blender programming.

But this is actually a new angle, which has been baking for a few months. I’m talking about making, DIY, electronics and robotics!

I haven’t abandoned Blender, far from it. I’ve only got deeper into stuff, now that I’m involved in a start-up utilizing Blender as our main development platform (more about that when I’ll be able to get into detail), and since I’ve been teaching Blender in college and makerspaces. What’s been keeping me from writing is mainly time, or lack thereof. But hopefully I’ll be able to write more often soon. Now for the issue at hand!


The world of robotics always fascinated me, but from a distance. I never thought I could actually get involved, and was certain this stuff is too arcane and complex for me to really get into grips with, at least unless I dedicated my life to it.

Gladly that’s not quite true anymore. Sure, truely complex robots and sophisticated AI require such arcane expertise that only few obtain. But the bar defining what’s “truly complex” has gone up significantly in the last few years, since capable and easily programable microcontrollers (such as the Arduino platform) became so readily available.

This is mostly a hobby for me, though I have plans for a number of more practical projects, particularly in the photography field. More about that in the future, hopefully.

Meanwhile, I’m making useless stuff. Before this project, I’ve made all kinds of simple stuff like a simple speed game, a larson scanner, an RGB LED controlled by an IR remote, and a super simple pong game with a joystick and a 8×8 LED matrix.

But this project redefines the “useless” part and gives it a literal meaning. No, seriously, this build is called the “useless box”, and it wonderfully lives up to its name.

Useless Box

In short: you turn on a switch, and a mechanical arm turns it off. The most useless box in the known universe.

So blatantly, hilariously useless, it’s impossible not to want one.

I saw a video showing this miracle of engineering on Facebook, and I was immediately hooked:

I later discovered some people have actually made even crazier versions of this concept:

And even a multi-switch version:

I’m not so greedy (or unemployed), I’ll settle for a single switch, single-arm type, but definitely with more interesting behavior than simple switch turning. Something like this, but with more randomized behavior, rather then a set sequence of behaviors.

Let’s get down to work!

After the persistent idea “must not rest until useless box is finished” got stuck in my head, I started thinking how I’ll make my own version of the thing. A box is fairly obvious, so I got a wooden one. Switch is clearly necessary, and I already had a few lying around. It evidently also needed a servo motor for the arm (and maybe another one for the box’s lid), and something to control the motors.

Since I knew I don’t want to settle for the simplest behavior, I needed a microcontroller to control the motor, and the Arduino platform I’ve been learning to use at Maestro Zvika Markfeld’s course was perfect for the job.

That’s enough to start building!

Da box

First thing to prep is the box. The UB’s lid has a static piece that holds the switch, and a moving piece that allows the arm to peek out and shut the switch off.

Wooden box
Lever switch (STDP)

Box cutter
Vernier caliper
Hot glue gun and glue drums
Soldering iron and solder


After cutting the lid, I used the caliper and a pen to mark the loose bit where I wanted the switch to sit. Then it was time to drill a hole for the switch and to screw it in.


Yeah, I know I didn’t put the bloody switch at the marked point. I figured out it should be closer to the edge for the arm to easily turn it of, and far enough from the other edge as to avoid making it uncomfortable to move by us humans.

The arm

Tower Pro SG90 mini-servo (or similar)
Various pieces of wood, small and large popsicle sticks
Metal angle
M5 nuts and bolts
Electrical tape (optional)

Hot glue gun
Dremel (or similar multi tool)

The heart of this build is that impertinent arm that keeps popping out of the lid and shutting the switch back off. I wanted it to look cool, and recalled I had a piece that should do the job, scrapped from an old detachable hard drive’s case. It was fairly solid and heavy, and looked awesome. Problem was I had no idea how to attach the thing to the servo’s cog. I ended up improvising something out of a small piece of wood, a nut and bolt, some hot glue and one of the servo’s origianl arms.


This turned to be a total failure. The whole thing wasn’t stable enough. The indirect connection between the heavy arm and the motor’s axis made it too unstable and inefficient to have the required strength, and it simply couldn’t move the switch’s lever.

At first I thought the precarious plastic cylinder the motor rested on was the problem. So I built a more stable wooden holder for the servo, and bolted it to the box’s floor.


But even with this new mount, I had no stable way to connect the heavy metal arm to the motor. If only I had a 3D printer!

Arm V2

I sang a short lament for the useless previous arm design and moved on to the next one. I had a pack of small wood sticks, so I grabbed a bunch, some hot glue and an M5 nut and bolt and made a new arm. This one looked ugly, but worked beautifully.

Useless Box ArmV2

Here’s the old (useless?) arm and the neat new arm in action:

Opening and closing the lid

Tower Pro SG90 mini-servo (or similar)
Scrapped wood and metal mounts and bits
M5 nuts and bolts
Zip ties

Hot glue gun

The next step was to create a mount and an arm for the lid and its dedicated Servo.

Unfortunately I forgot to take pics of this part… but it was a fairly simple and straightforward thing compared to the switch-arm.

I zip tied the motor to a small heavy piece of metal scrapped from a printer, and hot glued the metal base to the box’s floor. To connect the motor to the lid, I used another bit scrapped from a printer – a rather long mount made from a thin sheet of steel. I screwed it to the lid on one end, and glued it to one of the servo’s original spindles.

Writing the sketch

With this done, I simply needed to write the code that will define the box’s behavior. You can find this code here on GitHub.

I wrote six behavioral variations using three main functions: one for opening the lid, one for closing the lid, and another one for sending the arm to close the switch. Each has parameters controlling the movement speed, and the delay before and after the movement. I created two other functions for making it easier to do sligthly more complex things such as opening and shutting and lid several times and feinting.

I could have made this much more versatile and interesting, but after conquering the main challanges of this build, my motivation ran dry.

So, here’s the final version in action. Enjoy! And feel free to leave comments below or ask questions about stuff I forgot to mention 🙂

New addon: Snowflake generator

A post by a Google+ contact of mine recently caught my eye with a cool animated gif.

Koch Snowflake generator by Marco Cameriero

It showed a snowflake fractal rendered in 2D with growing complexity. I love fractals (who doesn’t?), and snowflake shapes are among the most beautiful of them. The post said that the image was generated by a nice little web-application, developed by Italian computer science student, Marco Cameriero.

His app generates what’s called a “Koch curve” or “Koch Snowflake” shape. I was intrigued and read more about these shapes in Wikipedia. The procedure to generate such a shape seemed fairly straightforward, so I decided to try and write a blender script that generates Koch Snowflake meshes.

The problem is that I’m not exactly an expert in trigonometry or linear algebra, so calculating the equilateral triangle based vertex positions was a bit of a handful for me.

Luckily, blender’s already has objects that take care of all the math behind the scenes (vectors, matrices, etc), so I found ways to use blender’s transformation tools and some very basic vector operations to avoid calculating vertex positions myself.

I’ll explain more about the algorithm in a moment, but first, for those not interested in Blender Python programming, here’s a download link for the Addon: DOWNLOAD.

For detailed installation and usage, see the WIKI PAGE.

How to use the script:



Updated: Video tutorial now added

Building the snowflake in Python:

To create a Koch snowflake, you need:

1. A basic polygonal mesh (triangle, rectangle, pentagon, etc ).
2. An object that will link this mesh geometry to the scene.
3. To iterate over the polygon’s edges, split them and create triangles at the center of each edge.
4. Repeat this process for as many iterations as specified by the user.

Steps 1 and 2 were solved before and all I had to do is reuse code written by others (open source rulez!!):

The calculations necessary to create a basic polygon already appear in the “curvaceous galore” add-on that comes bundled with Blender (thank you Jimmy Hazevoet & testscreenings!). The function I borrowed code from to do this is “StarCurve” (line 258).

The code for creating a new mesh from a provided list of vertices and edges, and creating an object that links this geometry to the scene is specified in the awesome Blender 2.5 API “Code Snippets” (thanks to the authors!).

Algorithm for creating the Koch snowflake from a basic polygon:

Since I’m pretty lame in math, I shied away from trying to calculate the entire shape, and the positions of each vertex based on equilateral triangle trigonometry. Instead, I went for an automation algorithm for creating this shape, that would mimic (to some degree at least) a manual modeling process.

The steps required to create the snowflake from a polygon are these:

1. Iterate over each edge.

2. Split each edge to 3 equal edges (using the mesh.subdivide operator).

3. Select the edge at the center of the 3 newly created edges.

4. Subdivide it again to two equal edges.


5. Select the central vertex.
6. Translate this vertex to a position and distance that will create an equilateral triangle between it and the other two vertices of the subdivided edge. This does require some calculations, which I’ll discuss later.


These 6 steps (if performed on all edges) define one “iteration” of the whole snowflake generating algorithm. The next iteration will go over all the new edges and do the same with each, thus creating a more complex fractal shape.

Concerns and possible caveats:

I had one major concern regarding this approach: when you subdivide an edge, you create new edges. How does this affect the “edges” collection? Are the new edges simply added at the end of the line, or is the whole list re-arranged?

And if we create a reference object to all mesh edges ( for instance: “edges =” ), will that reference still be valid after the subdivision, or will it become stale?

And what about the vertices? An edge is simply an index that’s associated with the pair of vertices (or vertex indices) that define it. So what if the vertices’ indices are rearranged when new verts are added?

It was pretty clear I can’t simply iterate over the mesh’s edges (, since this list will change dynamically with subdivisions.

To solve this, I created a static dictionary, that has an arbitrary edge index as a key, and a list containing the associated vertex indices as the value.

Example: { 0 : [ 0, 1 ], 1 : [ 1, 2 ], 2: [2, 0 ] }

But the concerns mentioned above are just as relevant to vertices as they are to edges: what happens when a new vertex is added due to a subdivision? is it added at the end of the list, or are all indices recalculated?

I tested it quickly in the Python Console, and found out that new vertices are added at the end, regardless of their position on the mesh. Yay!

If this wasn’t the case, I’d have no way to store the undivided edges’ information and iterate only over them in each fractal iteration. Which means I’d have no choice but to create all the verts manually and calculate their positions with complex math (unlikely).

Finding central edges and vertices via Set boolean operations:

After you subdivide an edge into 3 edges, all three are selected. You have no immediate simple way to know which one is the central edge, which must be subdivided again.

One way I came up with to identify the central edge, is to compare the vertex indices between the three edges. The central edge shares both its verts with the other two edges, while the peripheral edges share only one vertex with another edge. So if I find the edge with two shared vertices, I’ll find the central edge.

A relatively quick way to tell how many shared verts an edge has, is by using Set boolean operations.

If you have two sets, you can easily perform an intersection, union or symmetrical difference between the sets to get the shared elements, all elements or only the non-shared elements, accordingly:

o  = bpy.context.object         # Selected object
d  =                     # Object's data (geometry)
bm = bmesh.from_edit_mesh( d )  # Create BMESH object from object data
bv = bm.verts                   # Reference object's verts specifically

## Find innermost edge
# Create dictionary of selected edges' indices and their verts
selected_edges = {
    e.index : set([ v.index for v in e.verts ]) \
    for e in bm.edges if

# Innermost edge shares both its verts with the other edges
mid = 42  # Initialize with out-of-range index to to elicit error of algorithm fails
for i in selected_edges.keys():
    other_edges = set( selected_edges.keys() ) - set( [i] ) # Set Symmetrical Difference

    # check how many joint verts this edge has with the others
    num_of_joint_verts = 0
    for oe in other_edges:
        if selected_edges[i] & selected_edges[oe]: # Intersect vertex sets
            num_of_joint_verts += 1

    # The middle edge will have two joint verts
    if num_of_joint_verts == 2:
        mid = i # Record middle edge's index

# Select innermost edge (by selecting its verts)
bpy.ops.mesh.select_all(action = 'DESELECT') # Deselect all verts
for v in selected_edges[ mid ]:
    bv[ v ].select = True

bm.select_flush( True )

I used a similar technique to find the innermost vertex created after the central edge is subdivided again.
The edge is split into two edges, that have 3 vertices. The two edges share only one vertex, which is the central vertex.
So an intersection between the vertex sets of both edges will discover the central vertex:

##  Select innermost vert (shared vert between both edges)

# Create list of sets, each containing the indices of a selected edge's verts
selected_edges_verts = [
    set([ v.index for v in e.verts ]) for e in bm.edges if

# Find common vert by intersecting both vert sets then poping out the only member of the set
joint_vert = list(
    selected_edges_verts[0] & selected_edges_verts[1]

# Find the verts that aren't joint (via set symmetrical_difference)
other_verts = list(
    selected_edges_verts[0] ^ selected_edges_verts[1]

Translating the central vertex to create an equilateral triangle:
At first I did try to figure out the trigonometric relationships between the edges of an equilateral triangle, and maybe find a way to calculate the new position of the central vertex. But I didn’t find a quick solution (probably due to my lack of knowledge), and decided to try a different solution to this problem.

What I needed was in essence a translation vector. This needs to point outwards from the object origin and carry the vertex the distance require to create an equilateral triangle. To get that vector, first I subtracted the location vectors (coordinates) of the two peripheral vertices.


This resulted in a vector with the required length, that lies perpendicular to the Vector I needed to translate the vertex.
I then multiplied it with a rotation matrix (that can be created rather simply using a Matrix object), to change the direction of the Vector.


This resulted in a translation vector that I could use with the transform.translate operator:

# Calculate its new position: should create an equilateral triangle
vdiff = bv[ other_verts[1] ].co - bv[ other_verts[0] ].co
vrot  = vdiff * rot_matrix

# Select middle vert and translate it by the rotate vector
bpy.ops.mesh.select_all(action = 'DESELECT')
bv[ joint_vert ].select = True

bm.select_flush( True )

bpy.ops.transform.translate( value = tuple( vrot ) )

There’s another small piece of code I didn’t show here, meant to make sure the triangle’s edge is directed outwards and not inwards, but I think I probably digressed enough about the code already, and you’re welcome to explore the source further to see the other tricks I used.

Creating more complex models like the one displayed at the top of this post:

Obviously, there’s only so much you can do with an edge loop that looks like a snowflake fractal’s outline.

I might expand on this script one day to create faceted shapes and profiles, but at the moment I’m pretty satisfied with it, as it provides a basis to work with.

The shape shown at the featured image above has obviously been processed beyond what the script provides. Here’s how I did it:

1. After creating a hexagon based fractal with two iterations, I selected the all the verts and duplicated them.

2. I then scaled these duplicated verts inwards, then used the “Smooth Vertex” operator in them (can be found in the Tools Panel under “Deform”, or in the Special’s menu (shortcut: “W”) –> Smooth.

3. After getting a nice inner hub I used the Skin Modifier to create a 3D shape out of these two shapes.

4. I reduced the radius of each vertex using the “Ctrl + A” shortcut with all verts selected, and then applied the skin modifier.

5. The only thing left was to Bridge (loop tools) between areas of the inner and outer hubs (I chose two faces from each hub and bridged between them). To create a tapered bridge I set the bridge segments to 3 and the Strength to around 0.5 in Cubic interpolation mode.


Automated web testing with Selenium’s python webdriver

I recently started working as an automation engineer in Kampyle, a feedback service and BI startup. My role here is to establish a system for automated testing of the company’s various products.

I’ve done my fair share of automation before, though not in this field. So I’m still learning, but after working here for around a week, I already have several automated tests that seem to work nicely. During this week of research, learning and writing, I found that there’s some nice sources out there for using the tools my automated system is based on: Selenium and it’s python API.

But even there is some nice documentation and lots of useful stack overflow posts, I thought it would be nice to write a short intro of how to write selenium based tests for web services in Python. So here goes:

Install Selenium and Selenium-Python:

Selenium is a wonderful tool for emulating a user’s interaction with web browsers. You can either record and replay your actions as a real user with Selenium IDE, use one of the supported programming languages and write scripted tests using the WebDriver, or even establish a server hub for multi-platform testing.

To write test scripts in Python, you need to install the python-selenium module. This is easy through the pip package manager. If you don’t have pip, install it on your system. In Debian based Linux systems:

sudo apt-get install python-pip

Then use it to install the selenium module:

pip install selenium

You might need more dependencies, depending (ha!) on the type of browser you’re using. Read about this on the API’s page.

Getting into grips with Selenium’s python API

The APIs enable you to interact with browser’s through Selenium. Selenium takes care of sending your standard python commands to each browser type, despite the variations in each browser’s architecture. So with a nice relatively generic script, you can run scripts for Firefox, Chrome, IE, Safari etc, in different operating systems.

Selenium does that using a “WebDriver”, its standard representation for all browsers.This webdriver can perform various actions such as loading pages, searching for elements etc. These element objects can then send data depending on their type (textboxes, checkboxes, etc) and elicit browser events such as clicks.

Here’s a short example showing how to create a firefox type webdriver, then get a page:

from selenium import webdriver

# Set Selenium firefox browser object
browser = webdriver.Firefox()

# Step 1: Navigate to page
browser.get( page_address )

If you run this, you’ll see a new firefox window pop up and navigate to the page you specified. Simple and easy.
And if you want to test that the page loaded successfully, you can use unit tests and assert commands:

    msg = "Got to page"

A whole bunch of interesting tests

Test that you found a specific element in the page, through it’s id:

import unittest
from   selenium import webdriver
from   selenium.common.exceptions import NoSuchElementException

# Set Selenium firefox browser object
browser = webdriver.Firefox()

# Navigate to desired page
browser.get( desired_page )

element = browser.find_element_by_id( element_id )
except NoSuchElementException: "found: %s" % element_id )

Check if a specific element is of a desired class:

# Assert that the element is of a specific class
"desired class",
msg = "F.3. element is of desired class"

Now for a slightly more complicated one: logging in by typing a username and password, pressing the submit button, then making sure login was successful:

import unittest
from   selenium import webdriver
from   selenium.common.exceptions import TimeoutException

browser = webdriver.Firefox()
browser.get( login_page )

# Fetch username, password input boxes and submit button
# This time I'm now testing if the elements were found.
# See the previous exmaples to see how to do that.
username = browser.find_element_by_id( "username" )
password = browser.find_element_by_id( "password" )
submit   = browser.find_element_by_id( "submit"   )

# Input text in username and password inputboxes
username.send_keys( "me"         )
password.send_keys( "mykewlpass" )

# Click on the submit button

# Create wait obj with a 5 sec timeout, and default 0.5 poll frequency
wait = WebDriverWait( browser, 5 )

# Test that login was successful by checking if the URL in the browser changed
page_loaded = wait.until_not(
lambda browser: browser.current_url == login_page
except TimeoutException: "Loading timeout expired" )

# Assert that the URL is now the correct post-login page
msg = "Successful Login"

What’s next?

These few commands and tests provide quite a lot of options by themselves, but there’s plenty more to explore in the Selenium python module API (that for some reason is rather hard to find directly form google!).

There’s also the possibility of using the Selenium Server (formerly AKA “Selenium RC” or “remote control”) to create a hub for running distributed tests on multiple platforms. I spent a frustrating couple of days trying to get a basic server-client system to work, and ended up giving up and using a simple webdriver just to get the hang of the system.

I’ll probably end up writing my own hub server later on, but in the mean time, there’s a whole lot of automated tests to write!