The file is a LISP application. Use the APPLOAD command to load it into AutoCAD.
AutoLISP Solutions: Create Long Intermediate Terrain Contours 15 Sep, 2005 By: Cadalyst AutoLISP can form an intermediate contour that assumes a linear interpolation between the contour heights Rami Mann e-mailed a request to draw a polyline between two existing polylines representing terrain contours. His project is missing some contours, and he wants to form an intermediate contour assuming a linear interpolation between the contour heights. The AutoLISP solution is CONTOURS.LSP, which allows the user to select any two polylines (lightweight or 2D) and enter a precision number (default 100) for the number of segments in the resulting polyline. If the terrain changes height rapidly in some places and is flatter in others, then the contours will be close together in parts and may be far apart in other sections (figure 1). A bonus file I wrote, RPL.LSP, will come in handy to reverse the direction of any selected polyline.
Terrain contours with varying distances between them. The lengths of the polylines in figure 1 are about 6,500 units and 5,300 units for the outer and inner contours, respectively. Applying CONTOURS.LSP to the parts of the contours that are somewhat parallel shows better results than those that vary wildly (figure 2). The precision (number of segments) gave good results for anything over 200 but did not improve much between 300 and 2,000. It took about 1 second for 200 points and about 5 seconds for 1,000 points to generate the curve. A contour generated between two existing contours. Get the Code Download the files from Cadalyst's CAD Tips site and save them in AutoCAD's Support directory.
Use the Appload facility by selecting Tools / Load Application. Then select the CONTOURS.LSP and RPL.LSP programs from where you stored them. How to Use the CONTOURS Code After you load the code, the system prompts you to enter CT to start the program. To see this prompt, you may need to set your Command window size to 3 lines by dragging the Command window splitter bar appropriately.
If you are using AutoCAD 2006 and you are not using the Command line area, you can still enter CT to start. Then AutoCAD will prompt you to select two polylines. How the prompts are displayed will depend on the version of AutoCAD. I tested the code for AutoCAD 2004 and 2006. After you select the polylines, the Precision: prompt is displayed, and you can select Enter to accept the default value shown of 100 points. The intermediate contour is then automatically displayed.
It is assumed that the polylines (contours) run in the same direction, so they are logically parallel, and you do not therefore select any particular end of the chosen contours. The result is a polyline made up of line segments only, and you may want to convert it to a fit curve. If you encounter a problem in which the resulting intermediate contour bears no resemblance to the mid boundary, the selected polylines may not run in the same direction. To correct this problem, you need to enter RPL and select one of the contours to reverse its direction. I wrote RPL many years ago so the code is quite ancient, but it still works in AutoCAD 2004 and 2006.
It probably works for any version of AutoCAD from R13 onward. When you use RPL, a prompt tells you that the selected polyline was reversed in direction, but you will see absolutely no difference in its appearance. Programming Notes The number of segments in each contour polyline may vary greatly, and so it would not be possible to try to use the polyline segment endpoints as a way of interpolating the curves.
Another approach that I tested and later rejected was attempting to divide the lengths of the polylines into an equal number of parts, and then find the midpoint between each successive pair of such points. That approach gave inaccurate results, so I finally used the start and end parametric values for each curve, and divided those numbers equally by the precision number.
I then interpolated between each successive pair of points to form the midpoint that made up the resulting polyline. I used only straight line segments for the result, and for a reasonable precision the appearance is indistinguishable from arc segments. CONTOURS.LSP starts with my error handler and system variable manager functions, followed by CONTOUR, which sets up some initial conditions and calls GET-PLINES and the main function CONTOURS.