Draw 3D Screw Threads

1 Jun, 2002 By: Tony Hotchkiss

HELIX.LSP creates wire frame helical screw threads for 3D drawings.

Benny (no last name supplied) e-mailed a request to draw 3D screw threads in AutoCAD. HELIX.LSP creates a helical screw thread in the form of a surface model. The user supplies the thread pitch or the number of threads per inch, the outside diameter, the thread length, and the center point of the base of the thread. The user may also specify the resolution as low, medium, or high. Figure 1 shows two views of a typical thread produced by HELIX.LSP.

Figure 1. Examples of helical screw threads created with HELIX.LSP, then shaded.

Get and load the code
Download HELIX.LSP from Cadalyst's CAD Tips site and save the file in the AutoCAD support directory. From the AutoCAD Tools menu, choose Load Applications or enter Appload at the AutoCAD Command prompt. In the Load Applications dialog box, select the HELIX.LSP file from the support directory.

How to use HELIX.LSP
After the program loads, enter HLX to start the program. The first prompt asks you to:
Specify the Thread Pitch or [Tpi]:

You can enter a value for the thread pitch or enter T to specify the number of threads per inch. If you enter T, the routine prompts you for:
Number of Threads per Inch:

The next prompt asks you to enter the
Outside Diameter:
followed by
Thread Length:
Center Point:
Resolution: <Low>/Medium/High

Figure 2. HELIX.LSP creates a wire frame surface model of a helical screw.

The default resolution is low, so simply press <Enter> to select low resolution. The routine then creates a helical screw thread in the form of a wire frame surface model, as shown in figure 2. The thread shown in figure 1 was shaded after HELIX.LSP created the wire frame surface model. HELIX.LSP does not do the shading automatically.

Programming notes
I used Visual LISP from AutoCAD 2000 to write the program, so it should also work in AutoCAD 2002. I used no functions introduced after AutoCAD Release 13, so HELIX.LSP should work in those earlier versions as well, although I did not test this.

The program starts with my usual error function and system variable management functions. The main function, (helix), organizes the data produced by a call to the (getinput) function. It then calls (get-ptlist) to define three point lists. The function (make-3dpolyline) uses the point lists to create 3D polylines that form the basis of two ruled surfaces.

The system variable SURFTAB1 controls the density of the ruled surfaces. Its value is a combination of the resolution, the length, and the pitch of the thread. The resolution represents the number of surface tabulations in one complete thread, and its value is multiplied by the number of threads to give a total density of the ruled surfaces. The resolution values are 30, 50, and 70 for low, medium, and high, respectively. HELIX.LSP creates the ruled surfaces by using the standard command function.

Finally, the routine deletes the 3D polylines. The last few lines of the helix function show how it makes the polylines and ruled surfaces.

(make-3dpolyline ptlist1)
(setq pl1 (entlast))
(make-3dpolyline ptlist2)
(setq pl2 (entlast))
(make-3dpolyline ptlist3)
(setq pl3 (entlast))
(setv "SURFTAB1" (fix (* res(/ len pitch))))
(command "RULESURF" pl1 pl2)
(command "RULESURF" pl2 pl3)
(entdel pl1)
(entdel pl2)
(entdel pl3)

Threads of thought
Defining a series of points along a helical 3D polyline is a relatively simple programming operation. To make something that resembles the thread form, I decided to create three 3D polylines to represent the outer diameter and the inner, or root, diameter, followed by another outer diameter.

Figure 3. Three 3D polylines form the foundation for the screw.

For a single thread, this technique produces a V shape when ruled surfaces are applied successively between each of the outer diameter and the root diameter polylines. Figure 3 shows the ordering of the 3D polylines and the ruled surfaces that connect them. Polyline three is identical to polyline one except that it starts one pitch higher in the z-direction.

Arbitrary thread count
The procedure is complicated by the fact that the screw has an arbitrary number of threads depending on the length and the pitch. The program blends the first and last threads to form flat ends, as shown in figures 1 and 2, so it must differentiate between the first and last threads for each of the three 3D polylines.

This is done by setting center points 2 and 3 at one-half pitch and one whole pitch higher in the z-direction, respectively, as shown in the following code:

(setq data (get-input)
pitch (nth 0 data)
dia (nth 1 data)
len (nth 2 data)
cen (nth 3 data)
res (nth 4 data)
dia2 (- dia (* 1.3 pitch))
cen2 (list (car cen) (cadr cen) (/ pitch 2))
cen3 (list (car cen) (cadr cen) pitch)
ptlist1 (get-ptlist cen dia pitch len res)
ptlist2 (get-ptlist cen2 dia2 pitch len res)
ptlist3 (get-ptlist cen3 dia pitch len res)
) ;_ setq

HELIX.LSP then uses these new center points in the generation of point lists, as shown in this typical (if) statement that is part of the (get-ptlist) function.

(if (= cpt cen2)
(setq pt (polar cen (setq ang (+ ang ang-inc)) rad)
pt (list (car pt)
(cadr pt)
(setq ht2 (+ ht2 (/ z-inc 2)))
) ;_ list
plist (append plist (list pt))
) ;_ setq
(setq count (1+ count))
) ;_ progn
) ;_ if

Last word on screw threads
Until now, when I needed to use screw threads in a drawing, I simply made either a surface or a solid of revolution based on a zigzag polyline. This looks perfectly OK from a distance, but if you need a closer view of a helical thread form, HELIX.LSP could be a solution.

MDT makes threads the easy way
Note that Autodesk Mechanical Desktop can create a 3D helical sweep to automatically make a solid model of a thread form. Figure 4 shows Mechanical Desktop's convenient Helix dialog box. You can specify parameters such as the pitch, revolutions, height, orientation, start angle, diameter, and taper angle.

Figure 4. Mechanical Desktop's Helix command is the easy way to make a 3D threaded screw.

Figure 5. Screw form that results from using Mechanical Desktop's Helix command.

Figure 5 shows a solid model thread form based on a triangular cross-section created using Mechanical Desktop. A significant difference is that the Mechanical Desktop model does not have flat ends like the thread form generated by HELIX.LSP. However, you can easily rectify this by using the appropriate solid modeling Boolean operations to subtract a box from each end of the thread form.

About the Author: Tony Hotchkiss

AutoCAD Tips!

Lynn Allen

In her easy-to-follow, friendly style, long-time Cadalyst contributing editor and Autodesk Technical Evangelist Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD video tips. Subscribe to the free Cadalyst Video Picks newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!

Follow Lynn on TwitterFollow Lynn on Twitter

Are you responsible for any CAD management duties (conducting training, implementing software, establishing standards, etc.)?
Yes: I am a full-time CAD manager
Yes: CAD management is part of my job description
Yes: CAD management is not officially part of my job, but there's no one else to do it
Submit Vote

Download Cadalyst, Fall 2015

Download Cadalyst Magazine Special Edition