home *** CD-ROM | disk | FTP | other *** search
- /* CMD: Gear
- * Make gears of user defined size in Modeler
- * By Steve Koren Copyright © 1994 Steve Koren.
- */
-
- /* -- See if we have any parameters up front ------------------------------ */
-
- arg name teeth rad_inner rad_outer thickness Ax
-
- if name="" then name="Gear"
- else name=strip(name)
-
- if teeth="" then teeth=20
- if rad_inner="" then rad_inner=.4
- if rad_outer="" then rad_outer=.5
- if thickness="" then thickness=.1
- if Ax="" then Ax='Y'
- cen = 0 0 0
- flist = Angular Smooth
-
- /* -- Load proper function libraries -------------------------------------- */
-
- signal on error
- signal on syntax
-
- call addlib "rexxsupport.library", 0, -30, 0
- MATHLIB="rexxmathlib.library"
- IF POS(MATHLIB , SHOW('L')) = 0 THEN
- IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
- call notify(1,"!Can't find "MATHLIB)
- exit
- END
-
- libadd = addlib("LWModelerARexx.port",0)
-
-
- /* -- Generate our requester ---------------------------------------------- */
-
- call req_begin "Gear Generator"
-
- AxId = req_addcontrol("Axis", "CH",'X Y Z')
- TeethID = req_addcontrol("Teeth",'N')
- InnerID = req_addcontrol("Inner Radius",'N',1)
- OuterID = req_addcontrol("Outer Radius",'N',1)
- ThickID = req_addcontrol("Thickness",'N',1)
- TypeID = req_addcontrol('Type:','CV',FList)
- CenID = req_addcontrol("Center",'V',1)
- SurfId = req_addcontrol("Surface",'R')
-
- call req_setval AxId, 3
- call req_setval TeethID, 20,20
- call req_setval InnerID, 1,1
- call req_setval OuterID, 1.1,1.1
- call req_setval ThickID, .1,.1
- call req_setval CenID,0
- call req_setval TypeID,1
-
- /* -- Post our requester and ask for input -------------------------------- */
-
- if (~req_post()) then do
- call req_end
- exit
- end
-
- teeth = req_getval(TeethId)
- rad_inner = req_getval(InnerId)
- rad_outer = req_getval(OuterId)
- thickness = req_getval(ThickId)
- Ax = req_getval(AxId)
- name = req_getval(SurfId)
- cen = req_getval(CenId)
- gtype = req_getval(TypeID)
-
- call req_end()
-
- t_ang = 360.0 / teeth / 57.2957794
-
- /* -- Generate a polygon -------------------------------------------------- */
-
- vl=""
- cx = word(cen,1)
- cy = word(cen,2)
- cz = word(cen,3) - thickness/2
-
- call ADD_BEGIN()
- call SURFACE("___GEAR")
-
- do tooth=0 to teeth-1
- a1 = t_ang * tooth
- a2 = a1 + (t_ang*3/6)
- a3 = a1 + (t_ang*4/6)
- a4 = a1 + (t_ang*5/6)
-
- vl = vl add_point((rad_inner * sin(a1)+cx) (rad_inner * cos(a1)+cy) cz)
- vl = vl add_point((rad_inner * sin(a2)+cx) (rad_inner * cos(a2)+cy) cz)
- vl = vl add_point((rad_outer * sin(a3)+cx) (rad_outer * cos(a3)+cy) cz)
- vl = vl add_point((rad_outer * sin(a4)+cx) (rad_outer * cos(a4)+cy) cz)
-
- end
-
- if gtype=2 then do
- call ADD_CURVE vl
- end
- else do
- call ADD_POLYGON vl
- end
-
- call ADD_END()
-
- /* -- Make it part of the right surface ----------------------------------- */
-
- call SEL_MODE(USER)
- call SEL_POLYGON(CLEAR, NVGT, 1)
- call SEL_POLYGON(SET,SURFACE, "___GEAR")
-
- if gtype=2 then do
- call FREEZECURVES()
- end
-
- /* -- Generate proper thinkness ------------------------------------------- */
-
- call EXTRUDE(Z, thickness, 1)
-
- call CHANGESURFACE(name)
-
- /* -- Rotate the new gear into the proper orientation --------------------- */
-
- if Ax=1 then do /* X */
- call ROTATE(90, X, cen)
- end
- else if Ax=2 then do /* Y */
- call ROTATE(90, Y, cen)
- end
- else if Ax=3 then do /* Z */
- end
-
-
- exit
-
- syntax:
- error:
- call end_all
- t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
- exit
-