To do this automatically is a big program, which is why you get offers to do it for you.
We did it, with a kludge of code that probably would not fit your job or even run there, plus that code is someone's property now.
If you search more subjectively than just asking, you may find stuff.
One strong possibility, a slightly newer solution, but may help you:
CONTOURS.LSP by Tony Hotchkiss
http://aec.cadalyst.com/aec/article/articleDetail.jsp?id=180709
There is, or was, a plethora of brilliant code written in autolisp.
S