Deform a complex pattern along a 3d path, maintaining vertical I am trying to create a patterned railing for a curved staircase, like this:



Except that in my case, the staircase does not have a constant curve. This is a straight segment of the railing I am using:



What is the best way to do this? I have tried deforming the railing along a curve. I can get this to work for a horizontal path, but when I add a vertical element, the uprights of the banister do not remain vertical. By the first curve, the railing is no longer perpendicular to the floor and by the bottom of the staircase the railing is lying horizontally or even under the floor. 

I have tried using an array modifier with an empty, but the size of one segment is too large to follow the curvature of the stairs accurately and organically. I don't want to make the pattern smaller in this situation.

I have tried using a lattice, but the results are lumpy and it is hard to maintain a constant thickness. Additionally, since not all the parts of the railing are attached to one another, parts of the metalwork begin to protrude through the handrail when steep angles are needed, along with other unwanted deformations.

This is what I've got so far:


Thanks for your help.
One way to do this is to use the mesh deform modifier. The modifier works similar to a lattice but will give you much better control and much smoother deformation in this case. Here's how you could go about doing this:


Use an array modifier or whatever you need to get the railing to the approximate length for the curve.
Use a cube and create a box that fits around the railing closely. Add a number of edge loops to the cube on the long edges.
Create a Base Shape key and then add a second.
Add a Mesh deform modifier to the railing and select the cube you just made. The default settings should be fine so click bind. Depending on the complexity of the meshes this may take a bit.
Select the cube and make sure you have the second Shape Key selected (not the basis one). Now go into edit mode on the cube, and make the mesh follow the curve of the stairs. The cube should now deform the railing like a lattice does. If there are any parts sticking through the cube or not moving you can unbind the modifier, make the cube a bit bigger and rebind it. All of the railing will need to be inside the box for this to work.
When you leave edit mode, because of the shape key, the mesh will snap back to the unedited state. Slide the slider to 1 and it will move back.


The reason I think a shape key will help you here is because you may need to add more edge loops to the cube or adjust the length of the railing at some point. Whenever you change the number of vertices on either object the mesh deform modifier will have to be unbound and rebound. If you didn't use a shape key you would pretty much have to remake the cube or try to reposition it back to the original shape.