AutoLISP Solutions: Beveled Gears8 Sep, 2006 By: Tony Hotchkiss
Use code to automatically draw a beveled gear.
Since I wrote the Spurgear code some years ago, I've received several requests for a program to draw a bevel gear. The latest request is from Howard Lindsey, an AutoCAD high-school teacher in Inverness, Florida. Now at last I'm pleased to present BEVELGEAR.LSP and the dialog box file BEVELGEAR.DCL.
BEVELGEAR.LSP takes the gear pitch diameter and the numbers of teeth on the gear and pinion as input via a dialog box. The beveled gear is then automatically drawn using the intersection of the gear and pinion shafts as the origin point (0.0, 0.0 in world coordinates).
Figure 1. This shows a typical bevel gear in section view with some added notations.
I wrote the code in AutoCAD 2006 and have tested it in both 2006 and 2007, although it should also run in earlier versions such as 2004 and 2005.
Get the Code
Download the BEVELGEAR.LSP and BEVELGEAR.DCL files from Cadalyst's CAD Tips site. Save the file in AutoCAD's Support directory. Use the Appload facility by selecting Tools / Load Application, and then use the browser to select the file.
How to Use BEVELGEAR.LSP
To start the program, enter BG and the Bevelgear dialog box displays. The input choices here are the Gear pitch diameter, Number of gear teeth and Number of pinion teeth as shown.
Figure 2. Once you start the program, the Bevelgear dialog box appears.
The dialog box shows an image of the bevel gear that represents a gear and pinion with perpendicular shafts. This is the most common configuration for bevel gears, and it's the only one that I considered. When you click OK on the dialog box, the program automatically draws the gear with no further input needed. The appearance of the drawing depends on the design parameters that are included in the code (see the programming notes). See two typical renditions below with a gear ratio of 1 with 48 teeth, and a gear ratio of ¼ with 120 teeth on the gear.
Figure 3. The beveled gear with 48 teeth on both the gear and the pinion.
Figure 4. The beveled gear with 120 teeth on the gear and 30 teeth on the pinion.
There is no user control over the sizes of the shafts of either the gear or the pinion, and I leave it to you to stretch the geometry to suit any standard sizes that may be appropriate to your designs. I found it difficult to decide on particular sizes because the pitch diameters of the gear and pinion can vary considerably as shown in the figures. I simply used ratios of the pitch diameters, so there may be some odd sizes of shafts and lengths of the bushings for the shafts.
Bevel gear geometry. The diametral pitch P of bevel gears is defined as the number of teeth per inch of pitch diameter. The gear pitch diameter is shown as dg in the first figure. The working depth of the teeth (the addendum of the gear plus the addendum of the pinion) is 2/P as it is for spur gears. The gear addendum (shown in figure 1) varies from 1/P for a gear ration of 1, to 0.54/P for gear ratios of 6.8 or more. The gear ratio can be given in terms of either the numbers of teeth or the pitch diameters. The dedendum (also shown in figure 1) is defined as 1.25/P, as it is for spur gears.
The face width (b in figure 1) depends on either the diametral pitch P or on the pitch cone length L (defined in figure 1). Its value is the smaller of 10/P or L/3, and that is why the tooth face widths differ between figures 3 and 4. In figure 3, b is L/3, and in figure 4, it is 10/P.
Most of the above information comes from the book The Fundamentals of Machine Component Design by Robert Juvinall and Kurt Marshek, John Wiley and Sons, published in 2000.
Program modules. The program starts with my usual error handler and system variable management functions SETV and RSETV, which are used throughout the program as well as at the beginning section. The DRAW-GEAR-IMAGE function draws the picture in the dialog box.
I generally like to draw the images rather than use a slide file or slide library because that involves another file, and I like to only use the LSP and the DCL files. In larger projects, the DCL and LSP files can be compiled into a single executable VLX file, but slide files cannot be included in the set of files compiled. Compiled files can also be run from any directory without concern for the support directory that you should use for the noncompiled code. In this case, you can see that drawing the image in the dialog box takes a lot of lines of code, and so it's a trade off of number of files versus ease of programming.
The BEVELGEAR function calls GEAR-POINTS function that returns all of the points in lists to define the gear. The pinion points are calculated directly in the BEVELGEAR function. Two other functions, CREATE-OR-SET-LAYER that makes new layers in the drawing and DO-MIRROR that returns a set of points mirrored about a line between to given points, are functions that I've used before in other routines, so they were easy to incorporate into this code with minor modification.
For the gear sections of the drawing, I mirrored the calculated points with DO-MIRROR, but for the pinion I opted to use the VL-CMDF function to mirror the actual polyline about the x-axis using AutoCAD's Mirror command. The hatch was then added to the mirrored section of the pinion with the VL-CMDF function calling AutoCAD's Hatch command. In the calculation of the pinion points for the BEVELGEAR function, I found that for the larger gear ratios the pinion shaft diameter had to be limited to a size that would fit the pinion, so I used the rule as follows:
(if (<= gr 2.0)
(setq psr (* 0.0625 dg))
(setq psr (* 0.1 dp))
) ;_ end of if
to control the pinion shaft radius psr for gear ratios above and below 2.0. The effect of this is shown in the two gear drawings of figures 3 and 4 respectively. For small gear ratios, the shaft size for the pinion can be the same as that for the gear, but it must decrease as the pinion pitch diameter decreases.
The hatched sections of the gears are drawn with polylines as the hatch boundary, and the function DRAW-POLY does this as follows:
(defun draw-poly (plst Theta n / polyobj ang bulge)
(setq xylist nil)
(mapcar '(lambda (xy)
(setq xylist (append xylist (list (car xy) (cadr xy))))
) ;_ end of lambda
) ;_ end of mapcar
(setq polyobj (make-LWpolyline xylist)) ; polyline object
(setq ang (/ Theta 4))
(setq bulge (/ (sin ang) (cos ang)))
(if (= n 1)
(setq bulge (- bulge))
) ;_ end of if
(vla-SetBulge polyobj 1 bulge)
(vla-SetBulge polyobj 9 (- bulge))
(setq bulge 0.25)
(if (= n 1)
(setq bulge (- bulge))
) ;_ end of if
(vla-SetBulge polyobj 3 (- bulge))
(vla-SetBulge polyobj 5 bulge)
(vlax-put-property polyobj 'layer "Gearoutline")
(create-or-set-layer "Hatch" "green" "Continuous")
(setv "CLAYER" "Hatch")
(vl-cmdf "-HATCH" "S" (car plst) "" "")
) ;_ end of draw-poly
To get the radius drawn correctly in the mirrored polyline, I used the test shown to determine the sign of the bulge factor of some polyline segments, and then the SetBulge Visual LISP function to produce the appropriate fillet radius. DRAW-POLY calls the MAKE-LWPOLYLINE function which is shown here:
(defun make-LWpolyline (inv-plst / arr invpline)
(setq arr (vlax-make-safearray 5 (cons 0 (- (length inv-plst) 1))))
(vlax-safearray-fill arr inv-plst)
(setq invpline (vla-AddLightweightPolyline
) ;_ end of vla-AddLightweightPolyline
) ;_ end of setq
) ;_ end of make-LWpolyline
I used this function in my original Spur Gear routine, and the variable names INV-PLST and INVPLINE indicate its original use for drawing the involute curve of the spur gear.
As always, I look forward to receiving your comments and requests for AutoLISP Solutions. Contact me using the links below.
Autodesk Technical Evangelist Lynn Allen guides you through a different AutoCAD feature in every edition of her popular "Circles and Lines" tutorial series. For even more AutoCAD how-to, check out Lynn's quick tips in the Cadalyst Video Gallery. Subscribe to Cadalyst's Tips & Tricks Tuesdays free e-newsletter and we'll notify you every time a new video tip is available. All exclusively from Cadalyst!
Autodesk University 2013 - Exhibit Hall 4 Dec, 2013
New Video Demo: From Many CAD Systems, One 4 Dec, 2013
Revit 2014 Update Release 1 Now Available For Download - Crash Reductions or Enhancements? 19 Jul, 2013
How to Replace the Viewport Compass with your Company Logo 5 Jul, 2013